Dim str As String = ""
Dim cnn As New SqlConnection
cnn.ConnectionString = "Data Source=.;Integrated Security=SSPI;Initial Catalog=s53"
str = "Insert Into elect(dates,times,MeterId,Point,Place,Value,Pf,W,Kwh,Dif,Reponsible) Values (@dates,@times,@MeterId,@Point,@Place,@Value,@Pf,@W,@Kwh,@Dif,@Reponsible)"
cnn.Open()
If MessageBox.Show("คุณต้องการบันทึกข้อมูลใช่หรือไม่?", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim cmd As New SqlCommand(str, cnn)
For i As Integer = 0 To DataGridView1.RowCount - 1
With cmd
.Parameters.AddWithValue("dates", (DateTimePicker1.Value.AddYears(-543).ToString("yyyy-MM-dd")))
.Parameters.AddWithValue("times", (ComboBox1.Text))
.Parameters.AddWithValue("meterId", DataGridView1.Rows(i).Cells(0).Value)
.Parameters.AddWithValue("point", DataGridView1.Rows(i).Cells(1).Value)
.Parameters.AddWithValue("place", DataGridView1.Rows(i).Cells(2).Value)
.Parameters.AddWithValue("value", DataGridView1.Rows(i).Cells(3).Value)
.Parameters.AddWithValue("pf", (TextBox1.Text))
.Parameters.AddWithValue("W", (TextBox2.Text))
.Parameters.AddWithValue("Kwh", (TextBox3.Text))
.Parameters.AddWithValue("Dif", (TextBox4.Text))
.Parameters.AddWithValue("Reponsible", (TextBox5.Text))
End With
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Close()
Next
cnn.Close()
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "ข้อความ", MessageBoxButtons.OK, MessageBoxIcon.None)
End If
ต้องแก้ยังไง ช่วยด้วยนะคะ
Tag : .NET, Ms SQL Server 2008, VS 2008 (.NET 3.x)