13-10-18, 11:17 PM
(آخر تعديل لهذه المشاركة : 13-10-18, 11:24 PM {2} بواسطة asemshahen5.)
غير الى :
كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
InsertNewRowIn_CASE(TextBox1.Text, TextBox2.Text, TextBox3.Text)
End Subكود :
Public Sub InsertNewRowIn_CASE(ByVal TextBox1 As Int32, ByVal TextBox2 As String, ByVal TextBox3 As String)
Dim Cmd As New SqlClient.SqlCommand
With Cmd
.Connection = Conne_Dept
.CommandType = CommandType.Text
If TextBox3 = "" Then
.CommandText = "INSERT INTO Table_Product (Product_id , Product_name) VALUES ( @Product_id , @Product_name)"
.Parameters.Clear()
.Parameters.AddWithValue("@Product_id", SqlDbType.Int).Value = TextBox1
.Parameters.AddWithValue("@Product_name", SqlDbType.NVarChar).Value = TextBox2
Else
.CommandText = "INSERT INTO Table_Product (Product_id , Product_name, Product_date) VALUES ( @Product_id , @Product_name, @Product_date)"
.Parameters.Clear()
.Parameters.AddWithValue("@Product_id", SqlDbType.Int).Value = TextBox1
.Parameters.AddWithValue("@Product_name", SqlDbType.NVarChar).Value = TextBox2
.Parameters.AddWithValue("@Product_date", SqlDbType.DateTime).Value = TextBox3
End If
End With
Try
If Conne_Dept.State = 1 Then Conne_Dept.Close()
Conne_Dept.Open()
Cmd.ExecuteNonQuery()
Conne_Dept.Close()
Cmd = Nothing
MsgBox("تم الحفظ بنجاح")
Catch ex As Exception
Conne_Dept.Close()
MsgBox(Err.Description, MsgBoxStyle.Information)
Finally
If Conne_Dept.State = ConnectionState.Open Then Conne_Dept.Close()
End Try
End Subسبحان الله وبحمده سبحان الله العظيم و الحمد لله ولا اله الا الله والله اكبر
