Delete row in GridView problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • William LaMartin

    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.Odb c.OdbcException : ERROR [07001]
    [MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParamete r 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:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$
    ConnectionStrin gs:MysoftwareCo nnectionString %>"

    ProviderName="< %$ ConnectionStrin gs:MysoftwareCo nnectionString. 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=?">


    <SelectParamete rs>

    <asp:ControlPar ameter ControlID="txtU id" Name="?" PropertyName="T ext" />

    </SelectParameter s>


    <UpdateParamete rs>

    <asp:Paramete r Name="Descripti on" Type="String"/>

    <asp:Paramete r Name="Lat" Type="String" />

    <asp:Paramete r Name="Link" Type="String" />

    <asp:Paramete r Name="Lon" Type="String" />

    <asp:Paramete r Name="Map" Type="String" />

    <asp:Paramete r Name="Title" Type="String" />

    <asp:Paramete r Name="Uid" Type="String" />

    </UpdateParameter s>


    <DeleteParamete rs>

    <asp:Paramete r Name="Id" Type="Int32"/>

    </DeleteParameter s>



    </asp:SqlDataSour ce>

    <asp:GridView ID="GridView1" runat="server" AllowSorting="T rue"
    AutoGenerateDel eteButton="True "

    AutoGenerateEdi tButton="True" DataSourceID="S qlDataSource1" Style="z-index:
    102;

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

    </asp:GridView>

    </form>

    </body>


  • =?Utf-8?B?TWFuaXNo?=

    #2
    RE: Delete row in GridView problem

    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:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
    ConflictDetecti on="CompareAllV alues"
    ConnectionStrin g="<%$ ConnectionStrin gs:TestConnecti onString %>"
    DeleteCommand=" DELETE FROM [MasterTable] WHERE [num] = @original_num AND
    [fname] = @original_fname "
    InsertCommand=" INSERT INTO [MasterTable] ([fname]) VALUES
    (@fname)" OldValuesParame terFormatString ="original_{ 0}"
    SelectCommand=" SELECT * FROM [MasterTable]"
    UpdateCommand=" UPDATE [MasterTable] SET [fname] = @fname WHERE [num] =
    @original_num AND [fname] = @original_fname ">
    <DeleteParamete rs>
    <asp:Paramete r Name="original_ num" Type="Int32" />
    <asp:Paramete r Name="original_ fname" Type="String" />
    </DeleteParameter s>
    <UpdateParamete rs>
    <asp:Paramete r Name="fname" Type="String" />
    <asp:Paramete r Name="original_ num" Type="Int32" />
    <asp:Paramete r Name="original_ fname" Type="String" />
    </UpdateParameter s>
    <InsertParamete rs>
    <asp:Paramete r Name="fname" Type="String" />
    </InsertParameter s>
    </asp:SqlDataSour ce>

    </div>
    <asp:GridView ID="GridView1" runat="server"
    AutoGenerateCol umns="False" DataKeyNames="n um"
    DataSourceID="S qlDataSource1">
    <Columns>
    <asp:BoundFie ld DataField="num" HeaderText="num "
    InsertVisible=" False" ReadOnly="True"
    SortExpression= "num" />
    <asp:BoundFie ld DataField="fnam e" HeaderText="fna me"
    SortExpression= "fname" />
    <asp:CommandFie ld ShowDeleteButto n="True"
    ShowEditButton= "True" />
    </Columns>
    </asp:GridView>

    Hope this helps.

    Regards,
    Manish
    MESCIUS USA Inc. has JavaScript and .NET UI controls, datagrids, reporting solutions, spreadsheets, document APIs and more to take your applications further.


    "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.Odb c.OdbcException : ERROR [07001]
    [MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParamete r 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:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$
    ConnectionStrin gs:MysoftwareCo nnectionString %>"
    >
    ProviderName="< %$ ConnectionStrin gs:MysoftwareCo nnectionString. 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=?">
    >
    >
    <SelectParamete rs>
    >
    <asp:ControlPar ameter ControlID="txtU id" Name="?" PropertyName="T ext" />
    >
    </SelectParameter s>
    >
    >
    <UpdateParamete rs>
    >
    <asp:Paramete r Name="Descripti on" Type="String"/>
    >
    <asp:Paramete r Name="Lat" Type="String" />
    >
    <asp:Paramete r Name="Link" Type="String" />
    >
    <asp:Paramete r Name="Lon" Type="String" />
    >
    <asp:Paramete r Name="Map" Type="String" />
    >
    <asp:Paramete r Name="Title" Type="String" />
    >
    <asp:Paramete r Name="Uid" Type="String" />
    >
    </UpdateParameter s>
    >
    >
    <DeleteParamete rs>
    >
    <asp:Paramete r Name="Id" Type="Int32"/>
    >
    </DeleteParameter s>
    >
    >
    >
    </asp:SqlDataSour ce>
    >
    <asp:GridView ID="GridView1" runat="server" AllowSorting="T rue"
    AutoGenerateDel eteButton="True "
    >
    AutoGenerateEdi tButton="True" DataSourceID="S qlDataSource1" Style="z-index:
    102;
    >
    left: 5px; position: absolute; top: 149px">
    >
    </asp:GridView>
    >
    </form>
    >
    </body>
    >
    >
    >

    Comment

    • William LaMartin

      #3
      Re: Delete row in GridView problem

      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
      deleteparameter s section:

      <DeleteParamete rs>
      <asp:Paramete r Name="Id" Type="Int32"/>
      </DeleteParameter s>



      "Manish" <Manish@discuss ions.microsoft. comwrote in message
      news:43E88B6B-8D8A-4DCD-867F-A1FE6CADB307@mi crosoft.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:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
      ConflictDetecti on="CompareAllV alues"
      ConnectionStrin g="<%$ ConnectionStrin gs:TestConnecti onString
      %>"
      DeleteCommand=" DELETE FROM [MasterTable] WHERE [num] = @original_num AND
      [fname] = @original_fname "
      InsertCommand=" INSERT INTO [MasterTable] ([fname]) VALUES
      (@fname)" OldValuesParame terFormatString ="original_{ 0}"
      SelectCommand=" SELECT * FROM [MasterTable]"
      UpdateCommand=" UPDATE [MasterTable] SET [fname] = @fname WHERE [num] =
      @original_num AND [fname] = @original_fname ">
      <DeleteParamete rs>
      <asp:Paramete r Name="original_ num" Type="Int32" />
      <asp:Paramete r Name="original_ fname" Type="String" />
      </DeleteParameter s>
      <UpdateParamete rs>
      <asp:Paramete r Name="fname" Type="String" />
      <asp:Paramete r Name="original_ num" Type="Int32" />
      <asp:Paramete r Name="original_ fname" Type="String" />
      </UpdateParameter s>
      <InsertParamete rs>
      <asp:Paramete r Name="fname" Type="String" />
      </InsertParameter s>
      </asp:SqlDataSour ce>
      >
      </div>
      <asp:GridView ID="GridView1" runat="server"
      AutoGenerateCol umns="False" DataKeyNames="n um"
      DataSourceID="S qlDataSource1">
      <Columns>
      <asp:BoundFie ld DataField="num" HeaderText="num "
      InsertVisible=" False" ReadOnly="True"
      SortExpression= "num" />
      <asp:BoundFie ld DataField="fnam e" HeaderText="fna me"
      SortExpression= "fname" />
      <asp:CommandFie ld ShowDeleteButto n="True"
      ShowEditButton= "True" />
      </Columns>
      </asp:GridView>
      >
      Hope this helps.
      >
      Regards,
      Manish
      MESCIUS USA Inc. has JavaScript and .NET UI controls, datagrids, reporting solutions, spreadsheets, document APIs and more to take your applications further.

      >
      "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.Odb c.OdbcException : ERROR [07001]
      >[MySQL][ODBC 3.51 Driver][mysqld-5.0.27]SQLBindParamete r 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:SqlDataSo urce ID="SqlDataSour ce1" runat="server"
      >ConnectionStri ng="<%$
      >ConnectionStri ngs:MysoftwareC onnectionString %>"
      >>
      >ProviderName=" <%$
      >ConnectionStri ngs:MysoftwareC onnectionString .ProviderName
      >%>"
      >>
      >SelectCommand= "Select * from PIB where Uid=?"
      >>
      >UpdateCommand= "UPDATE PIB SET Description = ?, Lat = ?, Link = ?, Lon =
      >?,
      >Map = ?, Title = ?, Uid = ? WHERE Id = ?"
      >>
      >DeleteComman d ="DELETE FROM PIB WHERE Id=?">
      >>
      >>
      ><SelectParamet ers>
      >>
      ><asp:ControlPa rameter ControlID="txtU id" Name="?" PropertyName="T ext" />
      >>
      ></SelectParameter s>
      >>
      >>
      ><UpdateParamet ers>
      >>
      ><asp:Paramet er Name="Descripti on" Type="String"/>
      >>
      ><asp:Paramet er Name="Lat" Type="String" />
      >>
      ><asp:Paramet er Name="Link" Type="String" />
      >>
      ><asp:Paramet er Name="Lon" Type="String" />
      >>
      ><asp:Paramet er Name="Map" Type="String" />
      >>
      ><asp:Paramet er Name="Title" Type="String" />
      >>
      ><asp:Paramet er Name="Uid" Type="String" />
      >>
      ></UpdateParameter s>
      >>
      >>
      ><DeleteParamet ers>
      >>
      ><asp:Paramet er Name="Id" Type="Int32"/>
      >>
      ></DeleteParameter s>
      >>
      >>
      >>
      ></asp:SqlDataSour ce>
      >>
      ><asp:GridVie w ID="GridView1" runat="server" AllowSorting="T rue"
      >AutoGenerateDe leteButton="Tru e"
      >>
      >AutoGenerateEd itButton="True" DataSourceID="S qlDataSource1"
      >Style="z-index:
      >102;
      >>
      >left: 5px; position: absolute; top: 149px">
      >>
      ></asp:GridView>
      >>
      ></form>
      >>
      ></body>
      >>
      >>
      >>

      Comment

      Working...