对象引用未设置为提交按钮上的对象实例 [英] object reference not set to an instance of an object on submit button
本文介绍了对象引用未设置为提交按钮上的对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助。当我点击按钮然后出现此错误。
对象引用未设置为提交按钮上的对象实例
i need help. when i click the button and then this error is comming.
"object reference not set to an instance of an object on submit button "
try
{
btnUpload.Visible = true;
con = new SqlConnection("Data Source=.;Initial Catalog=DSIIDC2;Integrated Security=True");
con.Open();
string str = "insert into addcaasedetails(caseno,casetype) values(" + txtcaseno.Text + ",'" + txtcasetype.Text + "')";
cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables["addcaasedetails"] == txtcaseno.Text && ds.Tables["addcaasedetails"].ToString()==txtcasetype.Text.ToString())
{
btnUpload.Visible = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
推荐答案
这种错误的最佳建议是使用调试器。所以,调试你的程序并检查哪个对象是null
。
参见过去谢尔盖的答案 [ ^ ]了解更多详情。
注意:您正在尝试插入数据,所以......你正在使用 ExecuteNonQuery方法 [ ^ ]。
为了能够获取数据,请使用正确的SELECT
语句,然后你就可以使用DataSet
,Da taAdapter
等
The best advice for such of error is to use debugger. So, debug your programm and check what object isnull
.
See past Sergey's answers too[^] for further details.
Note: you're trying to insert data, so... you heave to use ExecuteNonQuery method[^].
To be able to fetch data, use properSELECT
statement, then you'll be able to useDataSet
,DataAdapter
, etc.
这篇关于对象引用未设置为提交按钮上的对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文