你這個(gè)語句寫的有點(diǎn)問題,delete語句后面直接應(yīng)該接“from”,不應(yīng)該接其他的東西,這是基本語法
創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供烏爾禾網(wǎng)站建設(shè)、烏爾禾做網(wǎng)站、烏爾禾網(wǎng)站設(shè)計(jì)、烏爾禾網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、烏爾禾企業(yè)網(wǎng)站模板建站服務(wù),10多年烏爾禾做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
方法有多種。
可以dataAdapter.Fill到數(shù)據(jù)表應(yīng)該,設(shè)置幾個(gè)command,再通過dataAdapter.Update就可以更新數(shù)據(jù)了。不過表要有一個(gè)關(guān)鍵的key吧。
另外一種直觀一點(diǎn):
也需要表有個(gè)關(guān)鍵key有就是關(guān)鍵字段。
你datagridview.reomveAt(index)同時(shí)執(zhí)行sqlcommand("delete * From table where keyFild='" key "'")就可以。
參考一個(gè)實(shí)例,如下:
Private Sub bitDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bitDelete.Click
Dim oraConn As New OracleConnection()
oraConn.ConnectionString = " data source=數(shù)據(jù)庫名字;user id=賬號;password=密碼"
oraConn.Open()
Dim id As String = DataGridView1.CurrentRow.Cells(0).Value.ToString().Trim()
Dim queryString = "delete from t where id ='" id號 "'"
Dim adapter As OracleDataAdapter = New OracleDataAdapter(queryString,oraConn)
Dim mark As DataSet = New DataSet
adapter.Fill(mark, "Mark")
MessageBox.Show("刪除數(shù)據(jù)成功!")
Dim adapter As OracleDataAdapter = New OracleDataAdapter("select * from t ORDER BY id", oraConn)
Dim score As DataSet = New DataSet()
adapter.Fill(score , "Score ")
DataGridView1.DataSource = score
DataGridView1.DataMember = score .Tables(0).ToString
oraConn.Close()
End Sub
Dim?myconn?As?New?OleDb.OleDbConnection
Dim?mycommand?As?New?OleDb.OleDbCommand
myconn.ConnectionString?=?"Provider=Microsoft.ace.OLEDB.12.0;Data?Source=C:\Users\Administrator\Documents\賬號密碼.accdb?"
myconn.Open()
mycommand.Connection?=?myconn
Dim?sql5?As?String?=?"delete?from?表3?where?userid='"??(TextBox1.Text)??"'"
mycommand.CommandText?=?sql5
mycommand.CommandType?=?CommandType.Text
mycommand.ExecuteNonQuery()
Dim?sql3?As?String?=?"update?表2?set?Balance=Balance-2?where?UserID='"??(TextBox1.Text)??"'"
mycommand.CommandText?=?sql3
mycommand.CommandType?=?CommandType.Text
mycommand.ExecuteNonQuery()
myconn.Close()
sQueryString是SQL(增刪查改)語句
public
Boolean
ExecSQL(string
sQueryString)
{
SqlConnection
con
=
new
SqlConnection(ConfigurationManager.AppSettings["conStr"]);
con.Open();
SqlCommand
dbCommand
=
new
SqlCommand(sQueryString,
con);
try
{
dbCommand.ExecuteNonQuery();
con.Close();
}
catch
{
con.Close();
return
false;
}
return
true;
}
}
建立一個(gè)類,明自己取,然后調(diào)用就是了
例如:
類
BC=NEW
類();
STRING
ist="INSERT
INTO
XX(1,2,3)VALUES(A,B,C)";
BC.ExecSQL(ist);
就可以了
(1)如果ComboBox中的不是通過數(shù)據(jù)綁定得到的,用ComboBox.Items.Clear?方法?從?ComboBox?中移除所有項(xiàng)。
'清除所有項(xiàng)
ComboBox1.Items.Clear()
'清除ComboBox1顯示
ComboBox1.ResetText()
(1)如果ComboBox中的是通過數(shù)據(jù)綁定得到的,在用ComboBox.Items.Clear?方法?從?ComboBox?中移除所有項(xiàng)之前,先斷開綁定的數(shù)據(jù)源。
'斷開數(shù)據(jù)源
ComboBox1.DataSource?=?Nothing
'清除所有項(xiàng)
ComboBox1.Items.Clear()
'清除ComboBox1顯示
ComboBox1.ResetText()