Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn.ConnectionString = strConnString
objConn.Open()
Dim intNumRows As Integer
strSQL = "SELECT COUNT(*) FROM customer WHERE CustomerID = '"& Me.txtCustomerID.Text &"' "
objCmd = New SqlCommand(strSQL, objConn)
intNumRows = objCmd.ExecuteScalar()
IF intNumRows > 0 Then
strSQL = "UPDATE ..... "
objCmd = New SqlCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
objCmd.ExecuteNonQuery()
Else
strSQL = "INSERT ..... "
objCmd = New SqlCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
objCmd.ExecuteNonQuery()
End IF
objConn.Close()
objConn = Nothing
Date :
2012-12-06 09:16:46
By :
mr.win
No. 2
Guest
ขอบคุณมากคับ mr.win
Date :
2012-12-10 20:00:35
By :
มะตูม
No. 3
Guest
Code (C#)
var dgv = from dgvr in dataGridView1.Rows.Cast<DataGridViewRow>()
where (string)dgvr.Cells[0].Value == textBoxCode.Text
select dgvr;
if (dgv.Count() > 0)
{
(from dgvr in dataGridView1.Rows.Cast<DataGridViewRow>()
where (string)dgvr.Cells[0].Value == textBoxCode.Text
select dgvr).ToList().ForEach(dgvr =>
{
dgvr.Cells[1].Value += Convert.ToInt32(textBoxAmount.Text);
dgvr.Cells[2].Value += Convert.ToInt32(textBoxAmount.Text) * Convert.ToInt32(textBoxPrice.Text);
})
}
else
{
dataGridView1.Rows.Add(textBoxCode.Text, Convert.ToInt32(textBoxAmount.Text), Convert.ToInt32(textBoxAmount.Text) * Convert.ToInt32(textBoxPrice.Text));
}