[英]My datagridview is not displaying data
I made a datagridview which was connected to a dataset. 我做了一个datagridview,它已连接到数据集。 The dataset itself has plenty of records, I've checked;
我已经检查过数据集本身有很多记录; but when I debug, the grid doesn't display ANYTHING, which is irritating because just a couple of days ago, this program of mine was working just fine.
但是当我调试时,网格什么也没有显示,这很令人讨厌,因为几天前,我的这个程序运行良好。 I haven't modified any code or file for that matter.
我没有为此修改任何代码或文件。 I just took a break from opening my project for a couple of days, and when I opened it again, boom, it's not working as well as before.
我刚打开项目几天就休息了一段时间,当我再次打开它时,繁荣起来,它的工作不如以前。 Here's the code that I use:
这是我使用的代码:
System.Data.SqlClient.SqlConnection con; //sweet connection object is created in this here line
masterDataSet custMaster; //this creates an AWESOME database object
System.Data.SqlClient.SqlDataAdapter da; //this sets up a data adapter named "da". kewl
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection(); //name of the sweet connection object above
custMaster = new masterDataSet();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\master.mdf;Integrated Security=True;User Instance=True"; //this tells windows where to find the database DORA STYLE
con.Open(); //this opens up the connection. I DON'T SAY?
MessageBox.Show("Database connection has been established succesfully.");
string sql = "SELECT * From custMaster";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
da.Fill(custMaster, "custMaster");
MaxRows = custMaster.Tables["custMaster"].Rows.Count;
da.Update(custMaster, "custMaster");
con.Close();
}
then, for inputting data, I have created a form with the following code. 然后,为了输入数据,我用以下代码创建了一个表单。 although I'm sure the error does not lie in this part, I'll type it in anyway:
尽管我确定错误不在于此部分,但是无论如何我都会输入它:
private void newCustbutton1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
DataRow dRow = custMaster.Tables["custMaster"].NewRow();
dRow[1] = a_newCust.Text;
dRow[2] = b_newCust.Text;
dRow[3] = c_newCust.Text;
dRow[4] = d_newCust.Text;
dRow[5] = e_newCust.Text.ToString();
dRow[6] = f_newCust.Text;
dRow[7] = g_newCust.Text.ToString();
if (radioButton1.Checked == true)
{
dRow[8] = radioButton1.Text;
}
else if (radioButton2.Checked == true)
{
dRow[8] = radioButton2.Text;
}
custMaster.Tables["custMaster"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(custMaster, "custMaster");
MessageBox.Show("Customer succesfully added!");
}
I'm pretty sure it has do with my connections. 我很确定这与我的联系有关。 Any help would be great!
任何帮助将是巨大的!
1 - Have you tried to put Integrated Security=SSPI? 1-您是否尝试过将Integrated Security = SSPI设置为?
2 - MaxRows = custMaster.Tables["custMaster"].Rows.Count; 2-MaxRows = custMaster.Tables [“ custMaster”]。Rows.Count; try to see how many rows ur datatable is returning?
尝试查看您的数据表返回多少行?
3 - is there an error that you are getting or just empty datagrid? 3-您正在获取错误还是只是空的datagrid? have you tried to run the debugger?
您是否尝试运行调试器?
I would comment but my rep's not high enough... Anyway, so the dataset still has data and the datagridview was displaying the data a few days ago but now it isn't? 我会发表评论,但我的代表不够高...总之,因此数据集仍然有数据,而datagridview在几天前正在显示数据,但现在不是吗? If this is the case, I don't know why it would be working a few days ago and now it isn't, but maybe you could try refreshing the datagridview after you load the dataset.
如果是这种情况,我不知道为什么几天前它会起作用,而现在却不起作用,但是也许您可以在加载数据集后尝试刷新datagridview。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.