【发布时间】:2016-03-06 13:57:11
【问题描述】:
我有一个包含两列 Keyword 和 Emotion 的 SQL Server 表。
我想在包含句子的字符串中搜索一个单词(在列Keyword 中指定)。例如:- 你好吗
我要执行两个查询:
我想搜索字符串是否包含“how”(
how在Keyword列中指定)..如果字符串中包含
how,我想显示对应的值存储在表格的Emotion列中
这是我的示例代码(可能完全错误:p):-
public partial class message : System.Web.UI.Page
{
string constring = ConfigurationManager.ConnectionStrings["AnonymiousSocialNetworkConnectionString"].ToString();
protected void btnsend_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = new SqlConnection(constring);
string value = txtmsg.Text;
con.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select emotion from messageanalysis where keyword CONTAINS'",con);
myReader = myCommand.ExecuteReader();
while(myReader.Read())
{
lblStatus.Text = myReader["emotion"].ToString();// **this label should Display corresponding value stored in Emotion(column)**//
}
}
}
【问题讨论】:
-
我不明白你为什么需要两个查询,你有一个就足够了。
-
我的意思是说我想要执行两个操作,即搜索一个单词并获取相应的值
-
嗯,这就是半 sql 的作用......所以......我没有得到你的问题或问题。
-
我提供的代码不起作用它给出了 sql 异常.. 所以我想修复这个代码
-
好的,那么,错误是什么?生成的完整 sql 是什么?
标签: c# sql .net sql-server database