你這是向sql后臺數(shù)據(jù)庫寫數(shù)據(jù)嗎?
專注于為中小企業(yè)提供成都網(wǎng)站制作、網(wǎng)站設計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)靜寧免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
sqldataadapter1.update 改須指定有效的updatecommand,我一直沒有看到
給你個例子你看吧:
'首先指定有效的UpdateCommand
sqlstr = "insert into Playlist(PlayName,PlayPath)values('" TextBox4.Text.Trim "','" TextBox5.Text.Trim "')"
Module1.Mycommand.CommandText = sqlstr
'增加新一行(此行必須,要不不能與后臺同步,并且后面調(diào)用update會出錯)
Module1.MyDataSet.Tables("Music").Rows.Add()
Module1.MyDataAdaPter.InsertCommand = Module1.Mycommand
Module1.MyDataAdaPter.Update(Module1.MyDataSet, "Music")
MsgBox("增加數(shù)據(jù)成功?。?)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlStr As String = "insert into tb values("
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
sqlStr = "'" DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(i) "'"
If i DataGridView1.Columns.Count - 1 Then sqlStr = ","
Next
sqlStr = ")"
Dim con As New SqlConnection(connectionString) '這個自己寫去
con.Open()
Dim cmd As New SqlCommand(sqlStr, con)
Try
Dim result As Integer = cmd.ExecuteNonQuery()
If result 0 Then
MsgBox "添加數(shù)據(jù)成功"
Else
MsgBox "添加數(shù)據(jù)失敗"
End If
Catch (ex As Exception)
MsgBox "添加數(shù)據(jù)過程發(fā)生異常,原因:" ex.Message
End Try
End Sub
用SQL數(shù)據(jù)庫。VB.NET是微軟公司在2002年推出的一種開發(fā)基于.Net平臺應用程序的開發(fā)語言,vb.net在單擊回車鍵時將數(shù)據(jù)寫入數(shù)據(jù)庫需要用SQL數(shù)據(jù)庫。
使用.net下的system.sql.sqlclint類庫下的sqlconnent;sqlcommand類進行寫入操作