我需要创建一个如下所示的应用程序. [英] I need to create an application like below....
本文介绍了我需要创建一个如下所示的应用程序.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个如下所示的应用程序....
应该有一些文本框.将数据输入文本框后,我需要单击添加按钮.那么数据应该包含在gridview以及我的数据库中...我该怎么做?
I need to create an application like below....
there should be some text box.after giving the data into the text box i need to click the add button. then the data should be included in the gridview as well as in my database...how should i do that?
推荐答案
您是否尝试过 ^ ]
将此代码放在您的button_click上,以在datagridview中添加行:
Have you tried google[^]
Right this code on your button_click to add rows in datagridview:
int row = dgvSubjects.Rows.Add();
dgvSubjects.Rows[row].Cells["ID"].Value = "0";
//this is just for your reference, as per your columns in grid you can update column names.
dgvSubjects.Rows[row].Cells["SubjectName"].Value = txtSubjectName.Text;
dgvSubjects.Rows[row].Cells["SubjectDetails"].Value = txtSubjectDetails.Text;
dgvSubjects.Rows[row].Cells["SubjectCategory"].Value = cmbSubjectCategoryGID.Text;
dgvSubjects.Rows[row].Cells["SubjectCategoryGID"].Value = cmbSubjectCategoryGID.SelectedValue;
dgvSubjects.Rows[row].Cells["DueDate"].Value = dtpDueDate.Value.ToShortDateString();
并将您的数据保存在数据库中,以供参考,您可以 ^ ]再来一次
And save your data in database, for reference you can google[^] it again
那有什么大不了的呢.
现在使用插入查询ob按钮单击:
So what is the Big deal.
Now Use insert query ob button click:
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ToString());
cn.Open();
// Insert Query According to Your Form
string qry = "insert into Table_Name([Your_Column1],[Your_Column2])VALUES(@Your_Column1,@Your_Column2)";
SqlCommand cmd = new SqlCommand(qry,cn);
cmd.Parameters.Add("@Your_Column1", SqlDbType.YourDataType).Value = TextBOX1.Text;
cmd.Parameters.Add("@Your_Column2",SqlDbType.VarChar).Value = DropDownList1.SelectedValue;
cmd.ExecuteNonQuery();
cn.close();
这篇关于我需要创建一个如下所示的应用程序.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文