且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在表格中插入值

更新时间:2023-01-22 16:49:01

您需要触发器...

阅读:
MSDN:触发器 [
You need triggers...

Read:
MSDN: Trigger[^]

Alternatively, if you need to add something else (you need some manual work) then you can use a stored procedure where you can have both inserts.
OR
have a transaction and commit once both the tables are updated.

Reading Good SQL book will be of great help.


尝试以下两个查询


对于table1

字符串str ==插入测试值(" + txtbox1.text +'',""+ txtbox1.text +"''....);
sqlcommand com = new sqlcommand(str,connection);
com.executenonquery();


对于表2

首先获取Uid的值

字符串str1 =从table2中选择Max(UID)";
sqlcommand com1 =新的sqlcommand(str1,connection);
int i =(convert.toint32(com.executeScaler().tostring()));
i = i + 1;

然后执行插入查询;
try following two query


For table1

String str=Insert into test values(''"+txtbox1.text+"'',''"+txtbox1.text+"''....);
sqlcommand com=new sqlcommand(str,connection);
com.executenonquery();


For table 2

first retrive the value of Uid

String str1="Select Max(UID) from table2";
sqlcommand com1=new sqlcommand(str1,connection);
int i=(convert.toint32(com.executeScaler().tostring()));
i=i+1;

then execute insert query;