ASP.NET C# Code

I can get the text below to populate my output.

How do I get the "eng" to populate with the data from the SQl Server?

It's always going to be a single record and a single field that's returned.

 private void QueryDatabase2()
        {
            strSQL99 = @"SELECT eng FROM tblCategoryWelcome WHERE category = 'oceanfront'";
            string conString = @"Data Source=mydata.com;Database=db1;UID=user;PWD=password";
            SqlConnection myConn = new SqlConnection(conString);
 
            SqlCommand cmd = new SqlCommand(strSQL99, myConn);
           
            eng = "Data Here";
            myConn.Close();
            //cmd.Close();
 
        }
Larry Bristersr. DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pollock_dCommented:
go
myConn.Open();
eng = cmd.ExecuteQuery();
myConn.Close();
0
pollock_dCommented:
oh no, i mean

eng = cmd.ExecuteScalar();
0
Larry Bristersr. DeveloperAuthor Commented:
pollock_d:

When I use your code I get
Compiler Error Message: CS0266: Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)

Source Error:
Line 1046:            SqlCommand cmd = new SqlCommand(strSQL99, myConn);
Line 1047:            myConn.Open();
Line 1048:            eng = cmd.ExecuteScalar();
Line 1049:

 When I added  eng = cmd.ExecuteScalar().ToString;
I get
Compiler Error Message: CS0428: Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method?

Source Error:
Line 1046:            SqlCommand cmd = new SqlCommand(strSQL99, myConn);
Line 1047:            myConn.Open();
Line 1048:            eng = cmd.ExecuteScalar().ToString;
Line 1049:

 
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

pollock_dCommented:
go

eng = cmd.ExecuteScalar().ToString();

it's a method..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
YAY!  HOT DOG!  WHEE!  WHOOPIE!!!

uh.....

Thanks.
0
pollock_dCommented:
haha
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.