469,267 Members | 1,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

Delete row in GridView problem

On webform, I am populating a GridView from a SQLDatasource based on a MySQL
table named PIB.

There is no vb code involved. Everything is done in the source for the aspx
page, provided below. The update works fine, but a delete of a row produces
the following error:

Exception Details: System.Data.Odbc.OdbcException: ERROR [07001]
[MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParameter not used for all
parameters
The table, PIB, involved has a primary key , Id, and I have worked on this
for some time with no solution. Does anyone know the answer?

Thanks

<body>
<form id="form1" runat="server">

<asp:TextBox ID="txtUid" runat="server" Style="z-index: 100; left: 14px;
position: absolute; top: 96px">JoeTestor</asp:TextBox>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:MysoftwareConnectionString %>"

ProviderName="<%$ ConnectionStrings:MysoftwareConnectionString.Provi derName
%>"

SelectCommand="Select * from PIB where Uid=?"

UpdateCommand="UPDATE PIB SET Description = ?, Lat = ?, Link = ?, Lon = ?,
Map = ?, Title = ?, Uid = ? WHERE Id = ?"

DeleteCommand ="DELETE FROM PIB WHERE Id=?">
<SelectParameters>

<asp:ControlParameter ControlID="txtUid" Name="?" PropertyName="Text" />

</SelectParameters>
<UpdateParameters>

<asp:Parameter Name="Description" Type="String"/>

<asp:Parameter Name="Lat" Type="String" />

<asp:Parameter Name="Link" Type="String" />

<asp:Parameter Name="Lon" Type="String" />

<asp:Parameter Name="Map" Type="String" />

<asp:Parameter Name="Title" Type="String" />

<asp:Parameter Name="Uid" Type="String" />

</UpdateParameters>
<DeleteParameters>

<asp:Parameter Name="Id" Type="Int32"/>

</DeleteParameters>

</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True" DataSourceID="SqlDataSource1" Style="z-index:
102;

left: 5px; position: absolute; top: 149px">

</asp:GridView>

</form>

</body>
Jun 27 '08 #1
2 2283
Hi William,

I tried the following code and it works fine. Please make sure your Primary
key is set as property to DataKeyNames property of GridView control.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
DeleteCommand="DELETE FROM [MasterTable] WHERE [num] = @original_num AND
[fname] = @original_fname"
InsertCommand="INSERT INTO [MasterTable] ([fname]) VALUES
(@fname)" OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [MasterTable]"
UpdateCommand="UPDATE [MasterTable] SET [fname] = @fname WHERE [num] =
@original_num AND [fname] = @original_fname">
<DeleteParameters>
<asp:Parameter Name="original_num" Type="Int32" />
<asp:Parameter Name="original_fname" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="fname" Type="String" />
<asp:Parameter Name="original_num" Type="Int32" />
<asp:Parameter Name="original_fname" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="fname" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="num"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="num" HeaderText="num"
InsertVisible="False" ReadOnly="True"
SortExpression="num" />
<asp:BoundField DataField="fname" HeaderText="fname"
SortExpression="fname" />
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
</Columns>
</asp:GridView>

Hope this helps.

Regards,
Manish
www.ComponentOne.com

"William LaMartin" wrote:
On webform, I am populating a GridView from a SQLDatasource based on a MySQL
table named PIB.

There is no vb code involved. Everything is done in the source for the aspx
page, provided below. The update works fine, but a delete of a row produces
the following error:

Exception Details: System.Data.Odbc.OdbcException: ERROR [07001]
[MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParameter not used for all
parameters
The table, PIB, involved has a primary key , Id, and I have worked on this
for some time with no solution. Does anyone know the answer?

Thanks

<body>
<form id="form1" runat="server">

<asp:TextBox ID="txtUid" runat="server" Style="z-index: 100; left: 14px;
position: absolute; top: 96px">JoeTestor</asp:TextBox>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:MysoftwareConnectionString %>"

ProviderName="<%$ ConnectionStrings:MysoftwareConnectionString.Provi derName
%>"

SelectCommand="Select * from PIB where Uid=?"

UpdateCommand="UPDATE PIB SET Description = ?, Lat = ?, Link = ?, Lon = ?,
Map = ?, Title = ?, Uid = ? WHERE Id = ?"

DeleteCommand ="DELETE FROM PIB WHERE Id=?">
<SelectParameters>

<asp:ControlParameter ControlID="txtUid" Name="?" PropertyName="Text" />

</SelectParameters>
<UpdateParameters>

<asp:Parameter Name="Description" Type="String"/>

<asp:Parameter Name="Lat" Type="String" />

<asp:Parameter Name="Link" Type="String" />

<asp:Parameter Name="Lon" Type="String" />

<asp:Parameter Name="Map" Type="String" />

<asp:Parameter Name="Title" Type="String" />

<asp:Parameter Name="Uid" Type="String" />

</UpdateParameters>
<DeleteParameters>

<asp:Parameter Name="Id" Type="Int32"/>

</DeleteParameters>

</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True" DataSourceID="SqlDataSource1" Style="z-index:
102;

left: 5px; position: absolute; top: 149px">

</asp:GridView>

</form>

</body>
Jun 27 '08 #2
Thanks for the reply. I tried to reply to this posting yesterday, but the
message was bounced back to me, so I will try again.

I actually got my code to work by removing all reference to the
deleteparameters section:

<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32"/>
</DeleteParameters>

"Manish" <Ma****@discussions.microsoft.comwrote in message
news:43**********************************@microsof t.com...
Hi William,

I tried the following code and it works fine. Please make sure your
Primary
key is set as property to DataKeyNames property of GridView control.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:TestConnectionString
%>"
DeleteCommand="DELETE FROM [MasterTable] WHERE [num] = @original_num AND
[fname] = @original_fname"
InsertCommand="INSERT INTO [MasterTable] ([fname]) VALUES
(@fname)" OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM [MasterTable]"
UpdateCommand="UPDATE [MasterTable] SET [fname] = @fname WHERE [num] =
@original_num AND [fname] = @original_fname">
<DeleteParameters>
<asp:Parameter Name="original_num" Type="Int32" />
<asp:Parameter Name="original_fname" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="fname" Type="String" />
<asp:Parameter Name="original_num" Type="Int32" />
<asp:Parameter Name="original_fname" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="fname" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

</div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="num"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="num" HeaderText="num"
InsertVisible="False" ReadOnly="True"
SortExpression="num" />
<asp:BoundField DataField="fname" HeaderText="fname"
SortExpression="fname" />
<asp:CommandField ShowDeleteButton="True"
ShowEditButton="True" />
</Columns>
</asp:GridView>

Hope this helps.

Regards,
Manish
www.ComponentOne.com

"William LaMartin" wrote:
>On webform, I am populating a GridView from a SQLDatasource based on a
MySQL
table named PIB.

There is no vb code involved. Everything is done in the source for the
aspx
page, provided below. The update works fine, but a delete of a row
produces
the following error:

Exception Details: System.Data.Odbc.OdbcException: ERROR [07001]
[MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParameter not used for all
parameters
The table, PIB, involved has a primary key , Id, and I have worked on
this
for some time with no solution. Does anyone know the answer?

Thanks

<body>
<form id="form1" runat="server">

<asp:TextBox ID="txtUid" runat="server" Style="z-index: 100; left: 14px;
position: absolute; top: 96px">JoeTestor</asp:TextBox>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:MysoftwareConnectionString %>"

ProviderName="<%$
ConnectionStrings:MysoftwareConnectionString.Prov iderName
%>"

SelectCommand="Select * from PIB where Uid=?"

UpdateCommand="UPDATE PIB SET Description = ?, Lat = ?, Link = ?, Lon =
?,
Map = ?, Title = ?, Uid = ? WHERE Id = ?"

DeleteCommand ="DELETE FROM PIB WHERE Id=?">
<SelectParameters>

<asp:ControlParameter ControlID="txtUid" Name="?" PropertyName="Text" />

</SelectParameters>
<UpdateParameters>

<asp:Parameter Name="Description" Type="String"/>

<asp:Parameter Name="Lat" Type="String" />

<asp:Parameter Name="Link" Type="String" />

<asp:Parameter Name="Lon" Type="String" />

<asp:Parameter Name="Map" Type="String" />

<asp:Parameter Name="Title" Type="String" />

<asp:Parameter Name="Uid" Type="String" />

</UpdateParameters>
<DeleteParameters>

<asp:Parameter Name="Id" Type="Int32"/>

</DeleteParameters>

</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True" DataSourceID="SqlDataSource1"
Style="z-index:
102;

left: 5px; position: absolute; top: 149px">

</asp:GridView>

</form>

</body>

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by NateDawg | last post: by
1 post views Thread by JasonK | last post: by
4 posts views Thread by Wannabe | last post: by
11 posts views Thread by Ed Dror | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.