如何在控制台中编写程序以在db中添加数据。 [英] How to write a program in console to add data in db.
本文介绍了如何在控制台中编写程序以在db中添加数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有两个字段Person和Incentive当我想在数据库中保存此信息时我的输出是以commamd提示我怎么能这样做?
我尝试过:
编写一个程序,在输出结束时在数据库中添加数据
Hello,i have a two fields Person and Incentive when i want to save this information in database when my output is comes in commamd prompt how can i do this?
What I have tried:
Write a program that add data in database when output is comes
推荐答案
读取用户的数据 - 这很简单,你知道怎么做。
然后:
Read the data from your user - that's trivial, you know how to do that.
Then:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)", con))
{
cmd.Parameters.AddWithValue("@C1", myValueForColumn1);
cmd.Parameters.AddWithValue("@C2", myValueForColumn2);
cmd.ExecuteNonQuery();
}
}
这篇关于如何在控制台中编写程序以在db中添加数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文