0

I am developing a project in C#.I am retrieving data from database to textbox.

In vb following code is used for retrieve data.

empcode.Text = IIf(IsDBNull(mRS("Accode").Value), "", mRS("Accode").Value)

And In C# I am using following code to retrieve data.

empcode.Text = mRS["Accode"] == System.DBNull.Value ? string.Empty : mRS["Accode"].ToString();

But in C# code it is giving following error in "mRS["Accode"]".

"Cannot apply indexing with [] to an expression type 'Recordset'".

Where mRS is Recordset.

Thanks & Regards

3
  • What do you mean Recordset? What is the type for mRS? Commented Nov 27, 2016 at 7:42
  • Your C# version is probably very old, before 4.0. It did not yet support default properties that are not indexers. So you have to write mRs.Fields["name"].Value. Try not to get stuck on 8+ year old versions of free software. Commented Nov 27, 2016 at 8:07
  • 1
    Hello, I am using visual studio 2015 and c# version is 6.0. Commented Nov 27, 2016 at 12:30

2 Answers 2

1

In VB the expression mRS("Accode") is expanded to mRS.Fieldset("Accode") automatically. So you should write mRS.Fieldset["Accode"] in C#.

Sign up to request clarification or add additional context in comments.

Comments

0
mRs.Fields["name"].Value 

worked for me.

1 Comment

Remember that Stack Overflow isn't just intended to solve the immediate problem, but also to help future readers find solutions to similar problems, which requires understanding the underlying code. This is especially important for members of our community who are beginners, and not familiar with the syntax. Given that, can you edit your answer to include an explanation of what you're doing and why you believe it is the best approach?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.