Thursday 15 May 2014

c# - SQL dataread to a textbox -


I am trying to get the data from the database into text! I have corrected the pasteing code and it does not give me any exception, but the problem is that it can not obtain the required data from the database that receives System.Data.SqlClient.SqlDataReader .

Please help me solve this problem ...

//// CODE ////

  Private Zero ReplaceBookmarkText (Microsoft .Office.Interop Word.Document Documents, String Bookmark Marks, String Text) {Object objI = 1; Object calculation = 7; Object oCount = Microsoft.Office.Interop.Word.WdConstants.wdForward; Object oUnit = Microsoft.Office.Interop.Word.WdUnits.wdCharacter; Int number; // Store your name here, where you want: bookmarkName = doc.Bookmarks.get_Item (ref objI) .name; // bookmarkind = doc.Bookmarks.get_Item (ref objI). the ending; // bookmark start = doc.Bookmarks.get_Item (referee objI). Start; Number = doc.Bookmarks.get_Item (referee objI) .change.moveand (referee oyunit, ref count); // bookmarkind = doc.Bookmarks.get_Item (ref objI). Start; String bookmark value = doc.Bookmarks.get_Item (referee objI) .Range.Text; MessageBox.Show (bookmarkValue); String db_name = ""; Try {sql_con = new SqlConnection (con_str); Sql_con.Open (); // "contactPerson where FirstName contact (Contact_ID =" + fNameTemp + ")"); // Select s_name from student where s_reg = '11 -ARID-4204 '// string sql_query = ("Select student from s_name where (s_reg =" + txtboxrollno + ")"); // "Choose from logging * * where password =" + "'Textbox1.Text'"; Sql_cmd = sql_con.CreateCommand (); String qrery = ("Select student from s_name where (s_reg =" + "'txtboxrollno.text'" + ")"); SQL Commands CMD = New SQL Commands (Curie, SKL_N); //sql_cmd.CommandText = ("Select student from s_name where (s_reg =" + txtboxrollno.Text.Trim ("+") "); Cmd.ExecuteNonQuery (); MessageBox.Show (cmd.ToString ()); SqlDataReader sdr; Sdr = cmd.ExecuteReader (); //textbox1.Text = sdr.ToString (); Db_name = textBox1.Text; While (sdr.Read ()) {//textBox1.Text = sdr ["s_name"] ToString (); Textbox1.Text = cmd.ExecuteScalar (). ToString (); //txtpatientid.Text = command.ExecuteScalar (). ToString (); //fNameTextBox.Text = sdr ["first name"]. ToString ();  
    

About something like this:

  sql_cmd = sql_con.CreateCommand (); String qrery = "select student from s_name where (s_reg = @s_reg)"; SQL Commands CMD = New SQL Commands (Curie, SKL_N); Cmd.Parameters.AddWithValue ("@ s_reg", txtboxrollno.Text); TextBox1.Text = cmd.ExecuteScalar () as string;   

There are some other things that I would recommend. But start with it. Before that the first result of the row will be, and it will be inserted into the text box.

No comments:

Post a Comment