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 SisodiyaRank #258 · 9.8K reputationPosted Mar 28, 2010, 9:08 PM EDT
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
kannan s65 reputationPosted Mar 28, 2010, 9:17 PM EDT
Thanks.. but i have list of student names... so how do store that values in sql database
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 28, 2010, 10:26 PM EDT
Do you want to save student names according to checkbox values??? please clear your question..
thanks
kannan s65 reputationPosted Mar 28, 2010, 11:50 PM EDT
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)
Jaish MathewsRank #225 · 11K reputationPosted Mar 29, 2010, 12:59 AM EDT
Use the BindingDataSource
http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 29, 2010, 1:06 AM EDT
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
kannan s65 reputationPosted Mar 29, 2010, 2:07 AM EDT
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
Jaish MathewsRank #225 · 11K reputationPosted Mar 29, 2010, 3:33 AM EDT
You need to update the DataAdapter. Check the link mentioned above
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 29, 2010, 5:29 AM EDT
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