C# 如何使用c比较条件中的自定义sql字段#
我有一个sql表,其中字段是qustionid、问题、答案、消息类型。我正在通过c#生成动态标签文本。 如何比较c#if else条件下的消息类型字段值 我的代码是-C# 如何使用c比较条件中的自定义sql字段#,c#,sql-server,C#,Sql Server,我有一个sql表,其中字段是qustionid、问题、答案、消息类型。我正在通过c#生成动态标签文本。 如何比较c#if else条件下的消息类型字段值 我的代码是- using (SqlConnection con = new SqlConnection(cs)) { string spName = @"dbo.[spUserResponseTest]"; SqlCommand cmd = new SqlCommand(spName, con); c
using (SqlConnection con = new SqlConnection(cs))
{
string spName = @"dbo.[spUserResponseTest]";
SqlCommand cmd = new SqlCommand(spName, con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserRequest", TextBox1.Text.Trim());
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
if (message-type == "text")
{
// message customize
}
string html = "<ul>";
while (reader.Read())
{
string bot_respons_list = String.Format("{0}", reader["Answer"]);
html += "<li>" + bot_respons_list + "</li>";
}
}
}
}
使用(SqlConnection con=newsqlconnection(cs))
{
字符串spName=@“dbo.[spUserResponseTest]”;
SqlCommand cmd=新的SqlCommand(spName,con);
con.Open();
cmd.CommandType=CommandType.storedProcess;
cmd.Parameters.AddWithValue(“@UserRequest”,TextBox1.Text.Trim());
使用(SqlDataReader=cmd.ExecuteReader())
{
if(reader.HasRows)
{
如果(消息类型=“文本”)
{
//消息自定义
}
字符串html=“”;
while(reader.Read())
{
string bot_response_list=string.Format(“{0}”,读卡器[“应答]);
html+=“- ”+bot\u response\u list+”
”;
}
}
}
}
要进行比较,首先需要将条件放入while(reader.Read()){}中。然后在if-else条件中将表的列号添加到reader[].toString()。在执行这些操作之前,请了解有关数据库适配器的更多信息
您尚未指定您所在的平台
while (reader.Read())
{
if (reader["*COLUMN NUMBER FOR message-type*"].toString() == "text")
{
// message customize
}
//other functions
}
我看不到你剩下的代码。但是如果
(message type==“text”)
中的消息类型应该来自您的阅读器的字段,并且您想检查它,那么只需写if(读卡器[“消息类型”].ToString()=“文本”)