PDA

View Full Version : سوال: update



mhbshn
سه شنبه 20 بهمن 1388, 12:15 عصر
از دستور ذيل براي درج اطلاعات در بانك استفاده كرده ام
از چه دستوري مشابه دستور ذيل براي update كردن بانك استفاده كنم ؟



conn.Open()
Dim strSql As String = " INSERT INTO info_personel (no_personel,no_meli,f_name,l_name)" & " Values(@no_personel,@no_meli,@f_name,@l_name)"
Dim Cmd As New OleDbCommand(strSql, conn)
With Cmd .Parameters.Add(New OleDbParameter("@no_personel", SqlDbType.NVarChar, 30)).Value = no_personel.Text
.Parameters.Add(New OleDbParameter("@no_meli", SqlDbType.NVarChar, 30)).Value = no_meli.Text
.Parameters.Add(New OleDbParameter("@f_name", SqlDbType.NVarChar, 30)).Value = f_name.Text
.Parameters.Add(New OleDbParameter("@l_name", SqlDbType.NVarChar, 30)).Value = l_name.Text
End With
Cmd.ExecuteNonQuery()

conn.Close()

jahanmanesh
سه شنبه 20 بهمن 1388, 12:19 عصر
Public Sub inserting()
connection = New OleDbConnection
connection.ConnectionString = constr
connection.Open()
strcom = New OleDbCommand
emptykey = 1
Call chechvalue()
If idupdate <> 0 Then
Try
strcom.CommandText = "Update Library set code = @code, author = @author ," & _
"publisher = @publisher, edition = @edition , price = @price " & _
", [language] = @language , description = @description , sold = @sold, bookname = @bookname where code = @code"
strcom.Connection = connection
strcom.Parameters.AddWithValue("code", Trim(code.Text))
strcom.Parameters.AddWithValue("author", Trim(author.Text))
strcom.Parameters.AddWithValue("publisher", Trim(publisher.Text))
strcom.Parameters.AddWithValue("edition", Trim(edition.Text))
strcom.Parameters.AddWithValue("price", Trim(price.Text))
strcom.Parameters.AddWithValue("language", Trim(language.Text))
strcom.Parameters.AddWithValue("description", Trim(description.Text))
strcom.Parameters.AddWithValue("sold", Trim(sold.CheckState))
strcom.Parameters.AddWithValue("bookname", Trim(bookname.Text))
strcom.ExecuteNonQuery()
connection.Close()
MsgBox("اطلاعات وارد شد")
idupdate = 0
emptykey = 0
Call chechvalue()
query.selecting()
Catch ex As Exception
MsgBox(ErrorToString)
End Try
Else

Try
strcom.CommandText = "INSERT INTO `library` (`code`, `author`, `publisher`, `edition`," & _
" `price`, `language`, `description`, sold, bookname) VALUES" & _
" (@code, @author, @publisher, @edition, @price, @language, @description, true , @bookname);"
strcom.Connection = connection
strcom.Parameters.AddWithValue("code", Trim(code.Text))
strcom.Parameters.AddWithValue("author", Trim(author.Text))
strcom.Parameters.AddWithValue("publisher", Trim(publisher.Text))
strcom.Parameters.AddWithValue("edition", Trim(edition.Text))
strcom.Parameters.AddWithValue("price", Trim(price.Text))
strcom.Parameters.AddWithValue("language", Trim(language.Text))
strcom.Parameters.AddWithValue("description", Trim(description.Text))
strcom.Parameters.AddWithValue("bookname", Trim(bookname.Text))
strcom.ExecuteNonQuery()
da.InsertCommand = strcom
connection.Close()
MsgBox("اطلاعات وارد شد")
emptykey = 0
Call chechvalue()

Catch ex As Exception
MsgBox(ErrorToString)
End Try

End If
If connection.State <> ConnectionState.Closed Then
connection.Close()
End If
connection.Dispose()
End Sub

سلام فرم Insert va UpDate من یکی بود و بر اساس اینکه IDUpdate که بش میدم تصمیم میگیره که آپدیت صورت بگیره یا درج اطلاعات