Answer the question
In order to leave comments, you need to log in
Why not find record in SQL SERVER database? Or is the request wrong?
New to asp.net. There is an application which self food. The user enters the IIN, presses the button, the Surname of the one whose IIN was entered by the user is displayed in TextBox3. Here is the code that actually works. Nothing happens if the IIN starts with the number 0. For example: IIN 951003357444 is found, but if IIN = 011020555442 nothing happens. That is, it does not search at all. Since this record is in the database.
try {
using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = @"Data Source=HP-NBOOK;Initial Catalog=LocNODB;Persist Security Info=True;User ID=cstest";
cn.Open();
SqlCommand cmd2 = new SqlCommand("SELECT IIN,FAM FROM Kontingent WHERE IIN LIKE " + TextBox1.Text, cn);
SqlDataReader rd2 = cmd2.ExecuteReader();
while (rd2.Read())
{
TextBox3.Text = (rd2["FAM"].ToString());
}
}
}
catch (SqlException ex)
{
}
Answer the question
In order to leave comments, you need to log in
Use query parameters, for example:
In code
cmd2.Parameters.Add("@iin", SqlDbType.NVarChar).Value = TextBox1.Text;
To begin with, a question. What type of field is in the database and what do we do in the request? Looking for occurrences, or equal?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question