I have a gridview with access and built with "select","edit" & "delete", the outside under gridview with the "add","cancel" buttons.
details:
select edit delet id name etc.
Textbox1
Textbox2
add cancel
ALL THE BUILT SELECT,EDIT,DELETE WRER WORKING, ONLY THE "ADD" BUTTON WAS NOT WORKING. So, I rebind the gridview with access - GOT THE DATASOURCE/DATASOURCEID PROBLEM, I delete the the datasourceid in the html, the "add" button actually is working and will refresh the gridview.
details:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="id"
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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridView()
End If
End Sub
Private Sub BindGridView()
' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
Dim dt As DataTable = New DataTable()
Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
conn.Open()
da.Fill(dt)
da.Dispose()
conn.Close()
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
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")
Catch ex As InvalidOperationException
MsgBox(ex.Message, MsgBoxStyle.Critical,"web")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical,"web")
End Try
con1.Close()
BindGridView()
End Sub
BUT NOW THE BUILT THE EDIT,DELETE ARE NOT WORKING - ERRORS,GRIDVIEW1 NOT HANDLE THE ROWEDITING, ROWDELETING,how to fix them?
Thanks.