Click here to Skip to main content
15,906,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
how can i use sqlDataAdapter to get any data from database(with sql Commands)and send to textbox object.
thanks
Posted

Try
conn.Open();
myCommnd.ExecuteScalar();
SqlDataAdapter da = new SqlDataAdapter(myCommnd);
DataTable dt = new DataTable();
da.Fill(dt);
textBox1.Text = dt.Rows[0].ItemArray[0].ToString();
 
Share this answer
 
You can refer this link

GetdataindatabasethroughSqlDataAdapterC.htm[^]

Hope it will help you
 
Share this answer
 
 
Share this answer
 
Check out these solutions above you will find how to use it.
Just an experience to add is:
- Do not pass variables directly into the query string, like:
C#
SqlCommand command = new SqlCommand("SELECT * FROM users WHERE Username =  " + user + " AND Password = " + password, connection);

- Please use: Parameters Add or AddWithValue to pass variables so that you will never get into troubles while execute query.

To tell the differences between these 2 methods, pleas check this
 
Share this answer
 
v4
why do you want to use sql command and sql adapter together? you can use anyone of them to get your result.
If in case with "sql command" you mean "sql query" then here you go.

I usually use this

SqlConnection conn = new SqlConnection();
       conn.ConnectionString = connStr;
       SqlDataAdapter da = new SqlDataAdapter("sqlquery", conn);
       DataSet ds = new DataSet();
       da.Fill(ds);
       if (ds.Tables[0].Rows.Count != null)
       {
           TextBox1.Text = ds.Tables[0].Rows[0][0].ToString();
       }


it will give you first column of first row in dataset. :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900