如何在任何列中转换数据 [英] How do I covert data in any column
本文介绍了如何在任何列中转换数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在一列中有0和1值(AnswerResult)。我想要有0的地方会自动显示不正确,并且有1则在浏览器上显示正确。
由于我是初学者,请给我一些建议
我尝试过:
I have 0 and 1 value in one column(AnswerResult) . I want where there is 0 it get automatically show "Incorrect" and where there is 1 it show "Correct" on browser.
As i am a beginner, please give me some suggestions
What I have tried:
private void detail()
{
string connection = ConfigurationManager.AppSettings["connection"].ToString();
SqlConnection con = new SqlConnection(connection);
con.Open();
SqlCommand com = new SqlCommand("SELECT case AnswerResult when 0 then 'Incorrect' When 1 then 'Correct' ELSE 'you have null value' END from t_AnswerSheet", con);
SqlDataAdapter sda = new SqlDataAdapter(com);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
}
推荐答案
尝试:
Try:
SqlCommand com = new SqlCommand("SELECT CASE WHEN AnswerResult = 0 THEN 'Incorrect' ELSE CASE WHEN AnswerResult = 1 THEN 'Correct' ELSE 'you have null value' END END FROM t_AnswerSheet", con);
或者更好的是,设置一个单独的可能响应表和生成它们的数字代码,并使用JOIN从中选择文本。当你习惯它时,它会更有效,更容易阅读。
Or better, set up a separate table of possible responses and the numeric code that generates them, and use JOIN to select the text from that. It's more efficient, and easier to read when you get used to it.
这篇关于如何在任何列中转换数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文