hi all,
i have some problem in vb.net windows application.
that is ,
i have a datagridview with two columns student_name,checkbox..
if any student present i have check the checkbox..else uncheck the check box..
but i dont know how do store these values in sql database using vb.net windows application....
Thanks & Regards,
kannan.s
Loading
Hirendra SisodiyaPosted Mar 29, 2010, 9:29 AM
you can update status for each row like:
For Each dtrow As DataGridViewRow In DataGridView1.Rows
Dim strQuery As String = "update table1 set status=" & CBool(dtrow.Cells(1).Value).ToString() & " where Student_Name ='" & dtrow.Cells(0).Value & "'"
'write code for Execute query
Next
'if you are using datasource property of datagridview than you can update database like:
'Code for fill the datagridview:
Dim db As SqlClient.SqlDataAdapter
Dim sqlCon As New SqlClient.SqlConnection("Initial Catalog=BMSIWorkFlow;Data Source= PSPL064\BMSI_APPSEXP;user id=sa;password=aeiouy")
sqlCon.Open()
db = New SqlClient.SqlDataAdapter("select [Name], status from tbl_Maint", sqlCon)
Dim Ds As New DataSet
db.Fill(Ds)
DataGridView1.DataSource = Nothing
DataGridView1.DataSource = Ds.Tables(0)
'now you can update datagridview means you can check or uncheck data
'Code for update data
db.Update(DataGridView1.DataSource)
thanks
Jaish MathewsPosted Mar 29, 2010, 7:33 AM
You need to update the DataAdapter. Check the link mentioned above
kannan sPosted Mar 29, 2010, 6:07 AM
The problem is , how do store these values in sql..
i explain
i have table with two column student_name,status
student_name ---------> name of the student
status ---------> if they present, yes, else false
db design
Student_name , status
But i have list of student_name...
for ex:
there are 50 students in class, 46 are present,4 absent,
i will check the checkbox for 46 student, but i wont check the checkbox for 4 student.
so after these i have to store these data in database.. what is the vb.net code to these datas in sql
Hirendra SisodiyaPosted Mar 29, 2010, 5:06 AM
Can you explain me what is problem for saving these values in database, means have you problem in reading data From DataGridView or in saving values in databasse??, do you want to save these information in only one column??
thanks
Jaish MathewsPosted Mar 29, 2010, 4:59 AM
Use the BindingDataSource
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx
kannan sPosted Mar 29, 2010, 3:50 AM
yes , i have to store the student name ..if they present i have to store ,both student name and checkbox value (true)... suppose if they absent , i have to store student name with checkbox value (false)
Hirendra SisodiyaPosted Mar 29, 2010, 2:26 AM
Do you want to save student names according to checkbox values??? please clear your question..
thanks
kannan sPosted Mar 29, 2010, 1:17 AM
Thanks.. but i have list of student names... so how do store that values in sql database
Hirendra SisodiyaPosted Mar 29, 2010, 1:08 AM
CheckBox in Datagridview always return True or False value, if your database has boolen field than you can save 1 for present or 0 for not present if you have strinh type field than you can do like:
if (DatagridView1.Rows[i].Cells[j].value = true)
{
return "Present";
}
else
{
return "Absent";
}
thanks
Please mark as answere if it helps