Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted
Comments
Karthik Harve 24-Apr-12 2:01am    
Have you tried anything..?? show your code.
Sandeep Mewara 24-Apr-12 5:25am    
Any effort? Tried anything?

Have you tried google[^]
Right this code on your button_click to add rows in datagridview:
C#
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
 
Share this answer
 
v3
Comments
sravani.v 24-Apr-12 2:02am    
My 5!
Prasad_Kulkarni 24-Apr-12 2:05am    
Thank You Sravani :)
So what is the Big deal.
Now Use insert query ob button click:

C#
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();
 
Share this answer
 
Comments
sourch7373 24-Apr-12 2:40am    
can u please be a lil more specific? my first column is running_sl_no(i.e decimal), 2nd is user_id(nvarchar),... and anything more other than cpying the code do i need to do? plz help....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900