C#中的数据库交互 [英] Database intergreation in C#
本文介绍了C#中的数据库交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是数据库集成的新手。我希望在文本框中输入的数据保存在访问数据库的某个列中,并且数据库应该在运行应用程序的列表框中加载。
任何想法
提前感谢
我尝试过:
i can从数据库加载数据但无法添加数据
iam new to data base integration. i want the data entered in the text box to be saved in a certain column of an access database and the database should load in a list box on running the application.
any ideas
thanks in advance
What I have tried:
i can load data from a database but cannot add data
推荐答案
尝试:
Try:
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();
}
}
这篇关于C#中的数据库交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文