这是窗体里按钮触发的事件:
private void btnInsert_Click(object sender, EventArgs e)
{
string b; int r;
db1 intser1 = new db1();
intser1.add( b,r );
if (r> 0)
{
MessageBox.Show("插入数据成功");
}
}这是dll文件里连接数据库的语句:
namespace mydl
{
public class db1
{
public void add(string a,int row)
{
string strConn = "Data Source=DESKTOP-DBGUUB5;Initial Catalog=chap2;Integrated Security=True";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSql =
"INSERT INTO Products (ProductID,ProductName,SuPPlierName,CategoryName,UnitPrice,UnitsInStock,Discount)VALUES ('0012', '双层蒸锅', '苏泊尔集团','厨具','129','100','f')";
SqlCommand comm = new SqlCommand(strSql, conn);
row = comm.ExecuteNonQuery();
a=Convert.ToString(comm);
conn.Close();
}
}
}
private void btnInsert_Click(object sender, EventArgs e)
{
string b; int r;
db1 intser1 = new db1();
intser1.add( b,r );
if (r> 0)
{
MessageBox.Show("插入数据成功");
}
}这是dll文件里连接数据库的语句:
namespace mydl
{
public class db1
{
public void add(string a,int row)
{
string strConn = "Data Source=DESKTOP-DBGUUB5;Initial Catalog=chap2;Integrated Security=True";
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
string strSql =
"INSERT INTO Products (ProductID,ProductName,SuPPlierName,CategoryName,UnitPrice,UnitsInStock,Discount)VALUES ('0012', '双层蒸锅', '苏泊尔集团','厨具','129','100','f')";
SqlCommand comm = new SqlCommand(strSql, conn);
row = comm.ExecuteNonQuery();
a=Convert.ToString(comm);
conn.Close();
}
}
}
解决方案 »
- 在VS2010中自带的MSChart图形控件有示例吗?
- 我的bin目录下的“Interop.msdk.dll”,好像是只将msdk.dll中用到的函数抽取出来。那么,如何将自己在.net框架下写成的x.dll引用后也
- C#的多语言化的实现
- 关于同一帐号禁止多人同时登陆的问题
- 用C#调用用C++写成的dll文件时,类型的匹配
- (小女子第一次用C#遇到难题,请教高人)怎样用c#调用智能ABC输入法???
- 如何设定让程序5秒刷新一次时间?
- 急:怎么移动PictureBox中的图片?
- 请教关于WebBrowser浏览器控件访问服务器问题?
- 请问在C#里怎样用汇编,还有如何使用windows的内部命令,比如 net send
- 在 System.EntryPointNotFoundException 中第一次偶然出现的“mscorlib.dll”类型的异常
- 通过360极速浏览器。。。。
int r=0;