本文介绍了将值插入数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的表名之一是Items,它具有五个字段ItemNo,Description,Qty,DoNumber和DoDate.

ItemNo,Description,Qty-值来自动态文本框,我使用了数据表来保存值,然后将其插入数据库.

我需要您的建议,如何将DoNumber和DoDate的值添加到Item表中.

我从方法生成的DoNumber值,对于Dodate,我有一个文本框.


谢谢

Hi

One of my table name is Items it has five fields ItemNo,Description,Qty,DoNumber and DoDate.

ItemNo,Description,Qty - values are from dynamic text box and i used datatable to save the value then inserting to database.

I need your suggestion how to add the value of DoNumber and DoDate to Item table.

DoNumber value i am generating from a method & for Dodate i have a text box.


Thanks

推荐答案

//using namespace when u use sql server//

using System.Data.SqlClient ;

// create sql connection //

sqlconnection con = new sqlconnection ("data souce= ur sql server name;initail catalog=ur database name;integreted security=true");
con.open();
sqlcommand cmd= new sqlcommand("insert into table_name values("'+textbox1.text+'","'+textbox1.text+'","'+textbox1.text+'")",con);
con.close();



string str=DoNumberMethod();//the method from which u want to pass the value for DoNumber .

sqlCommand cmd=insert into item values('"+txtItemNo.Text+"' , '"+txtQty.Text+"' , '"+txtDescription.Text+"' , '"+str+"' , '"+txtDoDate.Text+"')", sqlCon);



该方法的返回类型应为string:



the return type for the method should be string :

public string DoNumberMethod()
{
//return some string  value
}


这篇关于将值插入数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 00:13