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
私が間違っていることを助けてください
if チェックする データを挿入しない if データを挿入する チェックしない
誰かがこの質問を完全に手伝ってくれれば働く
> ExecuteReader: Connection property has not been initialized.
I am writing in C# then it is not working properly.
私はC#で書いていますが、正しく動作していません。