有人可以帮我解决这个问题吗?我在dsnewrow()中得到错误 [英] Can someone help me fix this problem? Im getting error in dsnewrow()

查看:58
本文介绍了有人可以帮我解决这个问题吗?我在dsnewrow()中得到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim cb As New SqlCommandBuilder(da)

Dim dsNewRow As DataRow

dsNewRow = ds.Tables(tbl_issues)。NewRow ()



dsNewRow.Item(ID)= txtID.Text

dsNewRow.Item(Item_code)= txtCode.Text

dsNewRow.Item(drug)= txtDrug.Text

dsNewRow.Item(剂量)= txtDosage.Text

dsNewRow。 Item(quantity)= txtQty.Text

dsNewRow.Item(lname)= txtlname.Text

dsNewRow.Item(fname)= txtfname.Text

dsNewRow.Item(mname)= txtmname.Text

dsNewRow.Item(date_issue)= DateTimePicker1.Text









ds.Tables(tbl_issues)。Rows.Add(dsNewRow)

da.Update(ds,tbl_issues)

MsgBox(添加到数据库中的新记录)



我尝试过:



可以有人帮我解决这个问题?我在dsNewRow中得到错误()

................................... .......................................

Dim cb As New SqlCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("tbl_issues").NewRow()

dsNewRow.Item("ID") = txtID.Text
dsNewRow.Item("Item_code") = txtCode.Text
dsNewRow.Item("drug") = txtDrug.Text
dsNewRow.Item("dosage") = txtDosage.Text
dsNewRow.Item("quantity") = txtQty.Text
dsNewRow.Item("lname") = txtlname.Text
dsNewRow.Item("fname") = txtfname.Text
dsNewRow.Item("mname") = txtmname.Text
dsNewRow.Item("date_issue") = DateTimePicker1.Text




ds.Tables("tbl_issues").Rows.Add(dsNewRow)
da.Update(ds, "tbl_issues")
MsgBox("New Record Added to the Database")

What I have tried:

can someone help me fix this problem? im getting error in dsNewRow()
..........................................................................

推荐答案

Quote:

LAST.exe中发生未处理的System.NullReferenceException类型异常

in dsNewRow = ds.Tables(tbl_issues)。NewRow()

An unhandled exception of type 'System.NullReferenceException' occurred in LAST.exe
in dsNewRow = ds.Tables("tbl_issues").NewRow()



你的 DataSet 不包含一个名为的表 tbl_issues



所以 ds.Tables(tbl_issues)返回没有



当你尝试拨打 NewRow 在返回的表上,你得到一个 NullReferenceException



你需要调试你的代码找出实际调用的表是什么,以及为什么你期望找到的表不存在。


Your DataSet doesn't contain a table called tbl_issues.

So ds.Tables("tbl_issues") returns Nothing.

And when you try to call NewRow on the returned table, you get a NullReferenceException.

You need to debug your code to find out what the tables are actually called, and why the table you were expecting to find doesn't exist.


无法用你的数据运行你的代码,我们不能帮助。



所以,它去吧取决于你。

在函数的第一行放置断点,并通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。
还要注意确切的错误消息说,包括任何内心错误。



对不起,但我们不能为你做到这一点 - 时间让你学习一个新的(非常非常有用)技能:调试!
Without being able to run your code with your data, we can't help.

So, its going to be up to you.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Also pay attention to exactly what the error message is saying, including any inner error.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于有人可以帮我解决这个问题吗?我在dsnewrow()中得到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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