'关于分页 只有DATASET可以分页
Sub datagrid_page(sender as object, e as datagridpagechangedeventargs)
    DataGrid1.currentpageindex
=e.newpageindex
    Rebind()
end sub


<datagrid  OnPageIndexChanged="datagrid_page">
带有参数的Insert
Sub Insert_Click(sender As Object, e As EventArgs)
        
dim myconn as sqlconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=jason")
    
dim datenow as datetime=DateTime.now
    
dim moneycount as decimal=val(textbox1.text)
    cmd
=New SqlCommand ( " insert into mis values ( @time_now, @Money, '" & textbox2.text & "', '" & textbox3.text & "' ) ", myconn)
    cmd.parameters.add(
"@time_now",datenow)
    cmd.parameters.add(
"@Money",SqlDbType.Decimal).value=moneycount
    cmd.connection.open()
    cmd.ExecuteNonQuery()
    myconn.close()      
    textbox1.text
=""
    textbox2.text=""
    textbox3.text=""
end sub
Sub DeleteRecord_Click(sender As Object, e As EventArgs)
    
dim myconnection as sqlconnection=new sqlconnection("server=localhost;uid=sa;pwd=123456;database=pub")
    
dim au_idString as string=""
    dim DelString as string=""
    dim i as integer=0
    
for i=0 to MYdatagrid.Items.Count-1
    
dim h as CheckBox
    h
=Ctype(MYdatagrid.Items(i).Cells(9).Controls(1),CheckBox)
    
if h.Checked = true then
        au_idString 
+=" or (au_id ='" + MYdatagrid.Items(i).Cells(0).Text + "')" '注意cell的数值为参考项的值
    end if
    
next

    
if au_idString.Length>0 then
        au_idString
=au_idString.Remove(0,4'移去前四个字符:"or "
        DelString = "Delete from authors where " + au_idString
        
dim DelRec as SqlCommand = new SqlCommand(DelString,myconnection)
        DelRec.Connection.Open()
        DelRec.ExecuteNonQuery()
        DelRec.Connection.Close()
    
end if
end sub


<Columns>
    
<asp:BoundColumn DataField="au_id" HeaderText="au_id"></asp:BoundColumn>
    
    
<asp:TemplateColumn HeaderText="Delete">
        
<ItemStyle horizontalalign="Center"></ItemStyle>
            
<ItemTemplate>
                
<asp:CheckBox runat="server" ID="del" />
        
</ItemTemplate>
    
</asp:TemplateColumn>
</Columns>
--------------------------------------------------------------------------------
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Sqlclient" %>
--------------------------------------------------------------------------------
sub Dr_Query( sqlstr as string)
        
dim myconn as sqlconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=jason")
        
dim mycomm as sqlcommand=new sqlcommand(sqlstr, myconn)
        
dim dr as sqldatareader
        myconn.open()
        dr
=mycomm.ExecuteReader()
        mydatagrid.datasource
=dr
        mydatagrid.databind()
        myconn.close()
end sub

--------------------------------------------------------------------------------
sub Non_Query( sqlstr as string)
    
Dim conn as sqlconnection=new sqlconnection("server=localhost;uid=sa;pwd=123456;database=pub")
    
Dim CMD As SqlCommand= new SqlCommand(sqlstr,conn)
    CMD.Connection.Open()
    CMD.ExecuteNonQuery()
    CMD.Connection.Close()
end sub

--------------------------------------------------------------------------------
sub Ds_Query( sqlstr as string)
    
dim myconnection as sqlconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=jason")
    
Dim adapter As New SqlDataAdapter()
    
Dim DS as DataSet =new DataSet()
    adapter.SelectCommand 
= new SqlCommand(sqlstr, myconnection)
    myconnection.open()
    adapter.fill(ds,
"user")
    mydatagrid.datasource
=ds
    mydatagrid.databind()
    myconnection.close()
end sub
Posted on 2004-12-16 14:51  Jason's WMI SQL Related Blog  阅读(1043)  评论(0编辑  收藏  举报