I have a web form that users can select dropdowns on, and fill a grid with the returned values. I need the grid to allow the user to make changes to the grid, and have those changes goto the DB. There is an error on the myID, myUser1... in the VB. It can't find the values for these. Do I need to Dim these, or what? Not sure what I am missing to get this to run? I checked out some other posts, and am not having any luck.
Found this post and tryed to use this as the basis for what I have thread855-1523389 but now I am stuck!
<asp:GridView
ID="GridView1"
runat="server"
Font-Size="X-Small"
Font-Names="Arial"
AutoGenerateColumns="True"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound"
BorderColor="Black">
<Columns>
<asp:commandfield ShowSelectButton="True" ShowEditButton="True">
</asp:commandfield>
<asp:boundfield DataField="ID" SortExpression="myID" HeaderText="myID">
</asp:boundfield>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/MYDB.mdb"
SelectCommand="SELECT * FROM [Test]" >
<UpdateParameters>
<asp:controlparameter Type="String" Name="myID" ControlID="gridview1" PropertyName="selectedrow.cells(0).text"/>
<asp:controlparameter Type="String" Name="myUser1" ControlID="gridview1" PropertyName="selectedrow.cells(1).text"/>
<asp:controlparameter Type="String" Name="myTime1" ControlID="gridview1" PropertyName="selectedrow.cells(2).text"/>
<asp:controlparameter Type="String" Name="myComments" ControlID="gridview1" PropertyName="selectedrow.cells(3).text"/>
<asp:controlparameter Type="String" Name="myWorkOrder" ControlID="gridview1" PropertyName="selectedrow.cells(4).text"/>
</UpdateParameters>
</asp:AccessDataSource>
Dim sql As String = "UPDATE Test SET ID = ?, User1=?, Time1=?, WorkOrder=?, Comments=? WHERE ID=?"
Using cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\Project1\App_Data\MYDB.mdb")
Using cmd As New OleDbCommand(sql, cnn)
cmd.CommandText = sql
cmd.Parameters.AddWithValue("@ID", ID)
cmd.Parameters.AddWithValue("@User1", UserName)
cmd.Parameters.AddWithValue("@Time1", Time1)
cmd.Parameters.AddWithValue("@Comments", Comments)
cmd.Parameters.AddWithValue("@WorkOrder", WorkOrder)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
GridView1.EditIndex = -1
DataBind()
End Using
End Using
Thanks in advance!
SMBrown
Found this post and tryed to use this as the basis for what I have thread855-1523389 but now I am stuck!
<asp:GridView
ID="GridView1"
runat="server"
Font-Size="X-Small"
Font-Names="Arial"
AutoGenerateColumns="True"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDataBound="GridView1_RowDataBound"
BorderColor="Black">
<Columns>
<asp:commandfield ShowSelectButton="True" ShowEditButton="True">
</asp:commandfield>
<asp:boundfield DataField="ID" SortExpression="myID" HeaderText="myID">
</asp:boundfield>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/MYDB.mdb"
SelectCommand="SELECT * FROM [Test]" >
<UpdateParameters>
<asp:controlparameter Type="String" Name="myID" ControlID="gridview1" PropertyName="selectedrow.cells(0).text"/>
<asp:controlparameter Type="String" Name="myUser1" ControlID="gridview1" PropertyName="selectedrow.cells(1).text"/>
<asp:controlparameter Type="String" Name="myTime1" ControlID="gridview1" PropertyName="selectedrow.cells(2).text"/>
<asp:controlparameter Type="String" Name="myComments" ControlID="gridview1" PropertyName="selectedrow.cells(3).text"/>
<asp:controlparameter Type="String" Name="myWorkOrder" ControlID="gridview1" PropertyName="selectedrow.cells(4).text"/>
</UpdateParameters>
</asp:AccessDataSource>
Dim sql As String = "UPDATE Test SET ID = ?, User1=?, Time1=?, WorkOrder=?, Comments=? WHERE ID=?"
Using cnn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=J:\Project1\App_Data\MYDB.mdb")
Using cmd As New OleDbCommand(sql, cnn)
cmd.CommandText = sql
cmd.Parameters.AddWithValue("@ID", ID)
cmd.Parameters.AddWithValue("@User1", UserName)
cmd.Parameters.AddWithValue("@Time1", Time1)
cmd.Parameters.AddWithValue("@Comments", Comments)
cmd.Parameters.AddWithValue("@WorkOrder", WorkOrder)
cnn.Open()
cmd.ExecuteNonQuery()
cnn.Close()
GridView1.EditIndex = -1
DataBind()
End Using
End Using
Thanks in advance!
SMBrown