繁体   English   中英

如何将SQL Server数据库文件添加到C#项目?

[英]How to add SQL Server database file to a C# project?

我是使用C#和SQL Server的初学者,我打算共享该项目,但是即使在安装该项目后,我的数据库仍需要主Database.mdf文件,问题是如何插入或附加干净的数据库文件(使用相同的表格和列)到已安装的项目中,没有错误?

顺便说一下,我的项目使任何人都可以收集有关“姓名,年龄和性别”的信息

string constring = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\pro pc\Documents\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
string Query = "insert into Sample (Name,Age,Gender) values ('" + this.txtname.Text + "','" + this.txtage.Text + "','" + this.gender + "')";

SqlConnection cn = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand(Query, cn);
SqlDataReader rd;

try
{
    cn.Open();
    rd = cmd.ExecuteReader();
    MessageBox.Show("Saved", "Saving Record");
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

脚本ID:

要执行的脚本的项目密钥。 要找到项目密钥,请在脚本编辑器中打开项目,然后选择“文件”>“项目属性”。

来源: https//developers.google.com/apps-script/execution/rest/v1/scripts/run#path-parameters

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM