OnEditCommand="DataGrid_Edit" onUpdateCommand="DataGrid_Update"
Sub DataGrid_Edit(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
Label3.Text = ""
myDataGrid.EditItemIndex = e.Item.ItemIndex
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
End Sub Sub DataGrid_Cancel(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
Label3.Text = ""
myDataGrid.EditItemIndex = -1
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
End Sub
Sub DataGrid_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim sid As Int16 = myDataGrid.DataKeys.Item(e.Item.ItemIndex)
Dim kind1 As String = e.Item.Cells(0).Text
Dim kind2 As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim mcon As String = CType(e.Item.Cells(2).Controls(1), TextBox).Text Dim conn As New OleDbConnection
conn.ConnectionString = StrCon
conn.Open()
strsql = "select * from akind where uname='" & Session("acountuser") & "' and kind1='" & kind1 & "' and kind2='" & kind2 & "' and id<>" & sid & ""
Dim strcomm As New OleDbCommand(strsql, conn)
Dim dread As OleDbDataReader
dread = strcomm.ExecuteReader
If dread.HasRows Then
Label3.Text = "该小分类已经存在"
Label3.ForeColor = Drawing.Color.Red
dread.Close()
conn.Close()
Else
dread.Close()
If kind1 = "支出" Then
strsql = "update akind set kind2='" & kind2 & "',mcon=" & mcon & " where id=" & sid & ""
Else
strsql = "update akind set kind2='" & kind2 & "' where id=" & sid & ""
End If
strcomm.CommandText = strsql
strcomm.ExecuteNonQuery()
conn.Close()
myDataGrid.EditItemIndex = -1
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
Label3.Text = "更新成功"
Label3.ForeColor = Drawing.Color.Red
End If End Sub
Sub DataGrid_Edit(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
Label3.Text = ""
myDataGrid.EditItemIndex = e.Item.ItemIndex
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
End Sub Sub DataGrid_Cancel(ByVal sender As System.Object, ByVal e As DataGridCommandEventArgs)
Label2.Text = ""
Label3.Text = ""
myDataGrid.EditItemIndex = -1
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
End Sub
Sub DataGrid_Update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Dim sid As Int16 = myDataGrid.DataKeys.Item(e.Item.ItemIndex)
Dim kind1 As String = e.Item.Cells(0).Text
Dim kind2 As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim mcon As String = CType(e.Item.Cells(2).Controls(1), TextBox).Text Dim conn As New OleDbConnection
conn.ConnectionString = StrCon
conn.Open()
strsql = "select * from akind where uname='" & Session("acountuser") & "' and kind1='" & kind1 & "' and kind2='" & kind2 & "' and id<>" & sid & ""
Dim strcomm As New OleDbCommand(strsql, conn)
Dim dread As OleDbDataReader
dread = strcomm.ExecuteReader
If dread.HasRows Then
Label3.Text = "该小分类已经存在"
Label3.ForeColor = Drawing.Color.Red
dread.Close()
conn.Close()
Else
dread.Close()
If kind1 = "支出" Then
strsql = "update akind set kind2='" & kind2 & "',mcon=" & mcon & " where id=" & sid & ""
Else
strsql = "update akind set kind2='" & kind2 & "' where id=" & sid & ""
End If
strcomm.CommandText = strsql
strcomm.ExecuteNonQuery()
conn.Close()
myDataGrid.EditItemIndex = -1
strsql = "SELECT id,kind1,kind2,mcon from akind where uname='" & Session("acountuser") & "'"
BindList()
Label3.Text = "更新成功"
Label3.ForeColor = Drawing.Color.Red
End If End Sub
解决方案 »
- 免费的午餐——编程利用Google日历API发短信
- 请问如何统计LIST中的数据?
- vs2005出问题了,高手帮忙看看
- DotNetNuke C# version
- C#中如何实现这样的效果?
- 救急!为什么无法更新datagrid的项?无法返回修改后的值
- axWindowsMediaPlayer 控件定位
- 请问如何设置使点击程序任意部分(除控件)可以移动程序?就像点窗顶那一条一样.
- C#写的程序怎么样才能在没有安装.net的机器上运行啊?
- C#萌新一个小问题
- Xml的CreateWhitespace和CreateSignificantWhitespace似乎一样啊?
- VS2005TS的团队特性??
private void button5_Click(object sender, System.EventArgs e)
{
}
里面有写什么代码
认真看看datagrid的教材吧
private void dataGridView1_CurrentCellChanged(object sender, System.EventArgs e)
{ try
{
NowID = dataGridView1.CurrentRow.Cells[0].Value.ToString();
}
catch (Exception ex)
{
MessageBox.Show("错误信息:"+ex.Message );
}
if (NowID != "")
{
SqlDataReader sdr = Function.SqlReader("select top 1 * from bq_note where ID=" + NowID, Function.connStr);
if (sdr != null)
{
if (sdr.Read())
{
textBox1.Text = sdr["note_body"].ToString();
textBox2.Text = sdr["note_name"].ToString();
textBox3.Text = sdr["note_date"].ToString();
}
sdr.Close();
}
}
}