我的代码有一个小问题,我试图将我的文本框值与数据库匹配,但我收到一条错误消息...
这是我的代码:
我的主要代码;
protected void btnAddNewTopic_Click(object sender, EventArgs e)
{
if (txtbAddNewTopic.Text == "")
{
MessageBox.Show("Please write topic!");
}
else if (goodob.Businness_Layer.AddNewTopic.NewTopicCheckSystem(txtbAddNewTopic.Text) == null)
{
MessageBox.Show("Your added topic is already in site!");
}
else
{
goodob.Businness_Layer.CreateNewTopic.crnewtopic(txtbAddNewTopic.Text);
MessageBox.Show("Your topic has successfully created!");
}
}
和我的校验码;
public static goodob.Businness_Layer.AddNewTopic NewTopicCheckSystem(string topic)
{
goodob.Businness_Layer.AddNewTopic xyz = null;
string query = @"SELECT [topic_name]
FROM topic
WHERE topic_name = @topic";
goodob.Class1 connection1 = new goodob.Class1();
connection1.sqlcommand.CommandText = query;
SqlParameter topicparam = new SqlParameter("@topic_name", SqlDbType.VarChar);
topicparam.Value = topic;
connection1.sqlcommand.Parameters.Add(topic);
System.Data.SqlClient.SqlDataReader reader = connection1.sqlcommand.ExecuteReader();
if (!reader.HasRows)
{
connection1.close_connection();
return null;
}
return xyz;
}
我在 connection1.sqlcommand.CommandText = query 中遇到错误;请帮我!