Q1. Please see this code below: Dim cn As New SqlClient.SqlConnection Dim cm As New SqlClient.SqlCommand 'Now this part is in form load' Dim s As String s = "data source=(local); uid=sa; pwd=sa; initial catalog=Salon" cn = New SqlClient.SqlConnection(s) cn.Open() 'Now this part is on click event of button' cm.CommandText = "Insert into Clients values('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text & "','" & Me.TextBox6.Text & "','" & Me.TextBox7.Text & "','" & Me.TextBox8.Text & "','" & Me.TextBox9.Text & "','" & Me.DateTimePicker1.Value & "')" cm.Connection = cn cm.ExecuteNonQuery() cn.Close() Now this insert query can insert values in all columns but it cant insert values in primary key and also cant insert pictures in sql database. So please guide me how to handle botht these problems. Send me the source code if possible.
your primary key is probably set as an Auto-Increment field which is NOT insertable into (It increases by X every time automatically)... When doing inserts do not include this field to insert into. Make sure your datatype is Image when inserting pictures. Load the image into byte() (byte array) and insert the blob.
ccoonen is right. If you need the Primary key that's inserted, you probably have to move your INSERT statement into a stored procedure. In the stored procedure you can use "SELECT @@IDENTITY AS ClientId" after your insert statement to retrieve the autoincrement Id that was just added.
A more reliable way to get the identity created is to use: SELECT SCOPE_IDENTITY() but @@Identity is fine too
Hey the fun is in trying out and experimenting. You will learn a lot experimenting rather than putting in code developed by some one else.