AllExperts > Experts 
Search      

VB.NET

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More VB.NET Answers
Question Library

Ask a question about VB.NET
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Syed Adeel Rizvi
Expertise
I can answers questions regarding web based and desktop based programming in VB.Net. Which can include XML, Custom Controls + Computer Hardware and Windows Turboshooting...etc. More Skills : 1 . PHP - > All Type Of CMS e.g. (Joomla,Drupul,PHPNuke...etc) 2 . ASP 3 . ASP.Net 4 . CMS 5 . MySql 6 . SQl Server 2000 & 2005 7 . Ms Access 8 . Web Designing 9 . Networking Turboshooting 10 . Windows Turboshooting 11 . Hardware Turboshooting All Type Of Work Related To IT I also Do Work as a Freelance as Application & Web Developer & Designer

Experience
i have 3 years work experience in software house and 4 years work experience for computer hardware and Networking..

Organizations
110 Solutions

Education/Credentials
Bsc (Honors)

 
   

You are here:  Experts > Computing/Technology > Basic > VB.NET > Another error message I dont understand

Topic: VB.NET



Expert: Syed Adeel Rizvi
Date: 4/8/2008
Subject: Another error message I dont understand

Question
Hi Ravi,

I am trying to update a table in a database that has four field of which there is no primary key. I successfully call up the information and amend it but when I click submit I get an error message. This method works fine in other pages I have coded but I am unsure why it does not on this page - I susspect that its something to do with the database but can't pin point the fault.

I have attatched the code and error message, thanks in advance Ravi your a life saver!

Here is the code for the page:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="server">

   Dim Con As New System.Data.OleDb.OleDbConnection
   

   Dim ds As New Data.DataSet
   
   Dim da As Data.OleDb.OleDbDataAdapter

   Dim sqlIPAddress As String
   
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
       If User.Identity.IsAuthenticated = False Then
           Server.Transfer("~/Website/Unauthorised.aspx")            
       End If
       Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
       'Opens the connection to the database
       Con.Open()
       'This is table spercific
       sqlIPAddress = "SELECT * FROM tbl_IPAddresses WHERE Tag = '" + Request("Tag") + "';"
       da = New Data.OleDb.OleDbDataAdapter(sqlIPAddress, Con)
       da.Fill(ds, "AmendIPAddress")

       Con.Close()
       
   End Sub
   
   Protected Sub cbDHCP_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
       If cbDHCP.Checked = True Then
           txtIPAddress.Text = ""
           txtIPAddress.Enabled = False
       Else
           txtIPAddress.Enabled = True
       End If
   End Sub

   Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs)
       Response.Redirect("~/Website/Administration/Ammend/PC/AmendPC.aspx")
   End Sub

   Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
       Con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Project\database\Backend.mdb"
       'Opens the connection to the database
       Con.Open()
       'This is table spercific
       sqlIPAddress = "SELECT * FROM tbl_IPAddresses WHERE Tag = '" + Request("Tag") + "';"
       da = New Data.OleDb.OleDbDataAdapter(sqlIPAddress, Con)
       da.Fill(ds, "AmendIPAddress")
       Dim cb As New Data.OleDb.OleDbCommandBuilder(da)
       ds.Tables("AmendIPAddress").Rows(0).Item(0) = txtTag.Text
       ds.Tables("AmendIPAddress").Rows(0).Item(1) = txtIPAddress.Text
       ds.Tables("AmendIPAddress").Rows(0).Item(2) = txtType.Text
       ds.Tables("AmendIPAddress").Rows(0).Item(3) = cbDHCP.Checked
       da.Update(ds, "AmendIPAddress")
       Con.Close()
       
       
       

       'Response.Redirect("~/Website/Administration/Ammend/PC/AmendPC.aspx")
   End Sub


   Protected Sub btnAmend_Click(ByVal sender As Object, ByVal e As System.EventArgs)
       txtTag.Text = ds.Tables("AmendIPAddress").Rows(0).Item(0)
       txtIPAddress.Text = ds.Tables("AmendIPAddress").Rows(0).Item(1)
       txtType.Text = ds.Tables("AmendIPAddress").Rows(0).Item(2)
       cbDHCP.Checked = ds.Tables("AmendIPAddress").Rows(0).Item(3)

       btnSubmit.Enabled = True
       btnAmend.Enabled = False
   End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
   <table border="0" cellpadding="1" cellspacing="1">
       <tr>
           <td colspan="2">
               Click here to start amending details
               <asp:Button ID="btnAmend" runat="server" OnClick="btnAmend_Click" Text="Amend" /></td>
       </tr>
       <tr>
           <td style="width: 100px">
               Tag</td>
           <td style="width: 100px">
               <asp:TextBox ID="txtTag" runat="server"></asp:TextBox></td>
       </tr>
       <tr>
           <td style="width: 100px">
               IP Address</td>
           <td style="width: 100px">
               <asp:TextBox ID="txtIPAddress" runat="server"></asp:TextBox></td>
       </tr>
       <tr>
           <td style="width: 100px">
               Type</td>
           <td style="width: 100px">
               <asp:TextBox ID="txtType" runat="server"></asp:TextBox></td>
       </tr>
       <tr>
           <td style="width: 100px; height: 18px">
               DHCP</td>
           <td style="width: 100px; height: 18px">
               <asp:CheckBox ID="cbDHCP" runat="server" OnCheckedChanged="cbDHCP_CheckedChanged" AutoPostBack="True" /></td>
       </tr>
       <tr>
           <td style="height: 18px; text-align: center;" colspan="2">
               <asp:Button ID="btnSubmit" runat="server" Text="Save" Width="75px" OnClick="btnSubmit_Click" /> <asp:Button
                   ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel" Width="75px" /></td>
       </tr>
   </table>
</asp:Content>



Here is the error message:

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Source Error:


Line 53:         ds.Tables("AmendIPAddress").Rows(0).Item(2) = txtType.Text
Line 54:         ds.Tables("AmendIPAddress").Rows(0).Item(3) = cbDHCP.Checked
Line 55:         da.Update(ds, "AmendIPAddress")
Line 56:         Con.Close()
Line 57:         


Source File: C:\Project\WebSite\Website\Administration\Ammend\PC\AmendPCIP.aspx    Line: 55

Stack Trace:


[InvalidOperationException: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.]
  System.Data.Common.DbDataAdapter.UpdatingRowStatusErrors(RowUpdatingEventArgs rowUpdatedEvent, DataRow dataRow) +196
  System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +662
  System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) +41
  System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) +181
  ASP.website_administration_ammend_pc_amendpcip_aspx.btnSubmit_Click(Object sender, EventArgs e) in C:\Project\WebSite\Website\Administration\Ammend\PC\AmendPCIP.aspx:55
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921



Many Thanks

Ben

Answer
Hello,

try to put this
after this
ds.Tables("AmendIPAddress").Rows(0).Item(2) = txtType.Text
ds.Tables("AmendIPAddress").Rows(0).Item(3) = cbDHCP.Checked
ds.AcceptChanges() '-<this new word
da.Update(ds, "AmendIPAddress")


thank you
any problem let me know and im not Ravi

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.