Delete row in GridView problem

W

William LaMartin

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.ProviderName
%>"

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>
 
M

Manish

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 said:
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.ProviderName
%>"

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>
 
W

William LaMartin

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 said:
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 said:
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.ProviderName
%>"

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>
 
A

Anetta Hayat

Thanks a Lot. It was helpful.
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.ProviderName
%>"

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>
On Wednesday, June 11, 2008 1:56 AM Manis wrote:
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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top