如何在vb.net中的访问数据库中插入空值

编程入门 行业动态 更新时间:2024-10-25 22:29:39
本文介绍了如何在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中的访问数据库中插入空值

本文发布于:2023-10-25 22:24:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   如何在   vb   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!