本文介绍了如何在vb中的访问数据库中插入空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai All 如何在访问db中插入空的vlaue。以下用于从anther数据库获取数据并存储在dt中,表单dt我将插入到新的db中,所以我不能告诉两个coloumn都有价值,一次有部门和deptid没有价值。这次我需要插入部门价值和deptid为空值
Hai All how to insert empty vlaue in access db.the following is used for get data from anther database and store in dt,form dt i will insert into new db,so i cant tell both coloumn have value,one time Department have and deptid not have value.in this time i need to insert department value and deptid as empty value
For Each row As DataRow In dt.Rows Dim con2 As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\admin\Desktop\Clean OCR DB\KM.mdb;Persist Security Info=False;Jet OLEDB:Database Password= Pa$$w0rd!238;") Dim cmd As OleDbCommand = New OleDbCommand("insert into Department([Department],[DeptID]) values(" + dt.Rows(0)("Department").ToString + "," + dt.Rows(0)("DeptID").ToString + ")", con2) con2.Open() cmd.ExecuteNonQuery() con2.Close() cmd.Dispose() Next请尽快回复我 问候 Aravind
pls reply me asap Regards Aravind
推荐答案w0rd!238;) Dim cmd As OleDbCommand = 新 OleDbCommand( 插入Department([Department],[DeptID])值( + dt.Rows( 0 )( 部门)。ToString + , + dt.Rows( 0 )( DeptID)。ToString + ),con2) con2.Open() cmd.ExecuteNonQuery() con2.Close() cmd .Dispose() 下一页 w0rd!238;") Dim cmd As OleDbCommand = New OleDbCommand("insert into Department([Department],[DeptID]) values(" + dt.Rows(0)("Department").ToString + "," + dt.Rows(0)("DeptID").ToString + ")", con2) con2.Open() cmd.ExecuteNonQuery() con2.Close() cmd.Dispose() Next
请尽快回复我 问候 Aravind
pls reply me asap Regards Aravind
确保列允许Nulls Make sure column is allow Nulls
你需要你的deptid自动递增吗? 如果是的话尝试: deptid int NOT NULL PRIMARY KEY IDENTITY(1,1) 别试试 deptid varchar(128)NULL do you require your "deptid" to auto increment? if yes try: deptid int NOT NULL PRIMARY KEY IDENTITY(1, 1) else try deptid varchar(128) NULL
更多推荐
如何在vb.net中的访问数据库中插入空值
发布评论