将值插入数据库表 [英] Insert value to database table

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

问题描述



我的表名之一是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();


嘿!在提问时请更具体,因为您的问题对我来说不清楚.我们需要有关您的问题的更多信息.
可以随便看看那里-MSDN- [如何:插入新记录进入数据库 [ ^ ]了解如何逐步添加值.
hey! please be more specific while asking question because your question is not clear for me. we need more information about your question.
whatever you can take a look there-MSDN-[How to: Insert New Records into a Database[^] to learn how to add values with step by step.


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
}


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆