<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="AccessDataSource1"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" /> <asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="AccessDataSource1"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
Dim sqlinsert As String
sqlinsert = "INSERT INTO sysdep (sysaccount,syspw)" & _
"VALUES(@sysaccount, @syspw)"
Dim cmd As New OleDbCommand(sqlinsert, con1)
cmd.Parameters.Add(New OleDbParameter("@sysaccount", TextBox1.Text))
cmd.Parameters.Add(New OleDbParameter("@syspw", TextBox2.Text))
Try
con1.Open()
cmd.ExecuteNonQuery()
Catch ex As OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
Catch ex As InvalidOperationException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message")
End Try
con1.Close()
End Sub
This is my program so far, I can add a new record, but I have to close all program and rerun it again, I will see the new record was in the gridview.
this program view;
gridview is on the top.
outside under the gridview there are two textboxes.
textbox1
textbox2
addbutton savebutton
(when click addbutton, the curson will go to the textbox1... after finish text in, click the savebutton, the savebutton will do the insert a new record, but how to do the refresh with the savebutton. Thanks.)