protected void Submit_Click(object sender, EventArgs e)
{
//string strCon = "Server=yourServer;Database=BuspassDb;User Id=Sa;Password=india;";
SqlConnection sqlConn = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand("select * from Console where Text = @TextTmp", sqlConn);
//cmd.CommandText = "CheckIfStringExists";
cmd.Parameters.AddWithValue("@TextTmp", txtString.Text);
//SqlParameter param = new SqlParameter();
//param.ParameterName = "@TextTmp";
//param.Value = txtString.Text;
//cmd.Parameters.Add(param);
try
{
sqlConn.Open();
SqlDataReader reader = cmd.ExecuteReader();
//reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
txtString.Text = (reader["Text"].ToString());
lblMessage.Text = txtString.Text + ".... is already exists";
}
else
lblMessage.Text = txtString.Text + "... is not exists";
txtString.Text = "";
sqlConn.Close();
//SqlConnection sqlCon = new SqlConnection(strCon);
//SqlCommand cmdd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "InsertConsole2";
cmd.Connection = sqlConn;
//cmd.Parameters.AddWithValue("@TextTmp", txtString.Text);
sqlConn.Open();
cmd.ExecuteScalar();
lblMessage.Text = txtString.Text + "....is Inserted";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
It shows the following error on the page
我做错了什么请帮助
如果检查数据不插入 如果插入数据不检查
如果有人帮助它帮助解决这个问题,那么工作
> ExecuteReader: Connection property has not been initialized.
I am writing in C# then it is not working properly.
我正在用 C# 编写,然后它无法正常工作。