السلام عليكم
احاول ادخال بيانات الى قاعدة البيانات عن طريق فورم vb.net 2010 ولكن للاسف لم اتمكن والكود جنني .
يشتغل مرة وحدة فقط وبعدين يعطيني ايرور علماً بان الاضافة تحتوي على صورة ايضا.
Syntax error near '2'
هذا الكود بالكامل .
If txtTitle.Text = "" Then
StLable.ForeColor = Color.Red
StLable.Text = "Please Insert The Book Title"
txtTitle.Focus()
Exit Sub
End If
If txtISBN.Text = "" Then
StLable.ForeColor = Color.Red
StLable.Text = "Please Insert the ISBN of the Book "
txtISBN.Focus()
Exit Sub
End If
'search if the Auther in DataBase
For i = 0 To Dt.Rows.Count - 1
If txtISBN.Text = Dt.Rows(i).Item("ISBN").ToString Then
StLable.ForeColor = Color.Red
StLable.Text = "Sorry This ISBN is already Set for another Book"
Exit Sub
End If
Next i
ConnectToDB("localhost", "LIBRARYDB")
Dim cmd As New SqlCommand
'
Dim SQL As String = "INSERT INTO [tblBooks]([Book_Title],[Book_Cat_ID],[Pub_Id]"
SQL = SQL & ",[Au_ID],[Edition],[Num_of_Copies],[ISBN],[Library_Serial]"
SQL = SQL & ",[Book_price],[Loss_Price],[Book_Remarks],[Book_Picture],[Book_cat_Serial])"
SQL = SQL & "VALUES('" & txtTitle.Text & "'," & cmbCatgory.SelectedValue & "," & cmbPublisher.SelectedValue & ","
SQL = SQL & cmbAuthor.SelectedValue & ",'" & txtEdition.Text & "'," & txtCopies.Text & ",'" & txtISBN.Text & "','" & txtLibSerial.Text & "',"
SQL = SQL & txtBookPrice.Text & "," & txtLossPrice.Text & ",'" & txtRem.Text & "',"
Dim MyImage As Image
If selectedPic Then
' Dim mstr As System.IO.MemoryStream
' Dim arrImage() As Byte
MyImage = PictureBox1.Image
Dim mstr = New System.IO.MemoryStream
MyImage.Save(mstr, System.Drawing.Imaging.ImageFormat.Png)
arrImage = mstr.GetBuffer
SQL = SQL & "@arrImage" & ","
Dim param As New SqlParameter("@arrImage", SqlDbType.VarBinary)
' Dim ImageData As Byte() = IO.File.ReadAllBytes(myfilelocation)
param.Value = arrImage
cmd.Parameters.Add(param)
Else
MyImage = Nothing
SQL = SQL & DBNull.Value & ","
End If
Dim num As Long
Dim admax As SqlDataAdapter = New SqlDataAdapter("select max(Book_cat_Serial) as Sr from tblBooks where Book_Cat_ID=" & cmbCatgory.SelectedValue & "", CN)
Dim dtmax As New DataTable
admax.Fill(dtmax)
If dtmax.Rows(0).Item(0).ToString = "" Then
num = 1
Else
num = (Val(dtmax.Rows(0).Item("Sr").ToString) + 1)
SQL = SQL & num & ")"
End If
SQL = SQL & num & ")"
dtmax = Nothing
admax = Nothing
cmd.CommandText = SQL
cmd.CommandType = CommandType.Text
cmd.Connection = CN
cmd.ExecuteNonQuery()
arrImage = Nothing
StLable.ForeColor = Color.Blue
StLable.Text = "Record added Successfully"
Dt.Clear() ' Clear the dataTable
adp.Fill(Dt) 'Reload the values
Rcount = Dt.Rows.Count - 1 'Move to the Last Record
ShowRecord() 'Show Record
cmdEdit.Enabled = True
cmdDelete.Enabled = True
cmdSearch.Enabled = True
cmd = Nothing
SQL = Nothingارجو المساعدة .

