Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,059
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Run-time exception thrown when using the following code...

    Originally Posted by pompai2005


    following code in vb script arising no error(i.e. debugging without any error, even then not inserting data from those three textbox control into the access database name.mdb having the table details,after clicking the button named btnadd)
    com.ExecuteNonQuery() Run-time exception thrown : System.Data.OleDb.OleDbException - Operation must use an updateable query.


    Code:
    sub btnadd(sender as object,e as eventargs)
    
    dim con as OleDBConnection
    dim com as OleDBCommand
    dim str as string
    dim i as integer
    
    try
    con=new OleDBConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\WebSite\database2\name.mdb;")
    con.open()
    str="insert into details values("&(t1.text)&","&(t2.text)&","&Cint(t3.text)&")"
    com=new OleDBCommand(str,con)
    i=com.Executenonquery()
    if i>0 then
    l1.text="one record added"
    end if
    catch es as exception
    l1.text=es.message
    finally
    con.close()
    end try
    
    end sub
    --------------------
    Code:
    <form id="Form1" method="post" runat="server">
    
    <asp:button id="subbtn" onclick="btnadd" Runat="server" Text="run query"></asp:button>
    
    <asp:datagrid id="dtgrid" Runat="server" Width="378px" Height="213px" BorderColor="#ff00ff" AlternatingItemStyle-Font-Bold="True" AlternatingItemStyle-BorderColor="#ff0000"></asp:datagrid>
    
    <asp:TextBox ID="t1" Runat="server"></asp:TextBox><br>
    <asp:TextBox ID="t2" Runat="server"></asp:TextBox><br>
    <asp:TextBox ID="t3" Runat="server"></asp:TextBox><br>
    
    </form>

    SOLUTION???????????

    Anirban Chakraborty
    pompai2005@gmail.com
    Last edited by vinyl-junkie; 08-20-2008 at 01:40 AM. Reason: Added code tags
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #2
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,083
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Look at the value of str. The syntax of your insert command may be off. I'm going to take a guess at what it should be:

    Code:
    str="insert into details values(" & t1.text & "," & t2.text & "," & Cint(t3.text) & ")"
    or maybe:

    Code:
    str="insert into details values(" & t1.text & "," & t2.text & "," & t3.text & ")"
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    38
    Thanks
    0
    Thanked 2 Times in 2 Posts
    this is works if you did not figure it out

    Code:
        Dim con As OleDbConnection
        Dim com As OleDBCommand
        Dim str As String
        Dim i As Integer
        Dim strt1 As String = Trim(t1.Text)
        Dim strt2 As String = Trim(t2.Text)
        Dim intt3 As Integer = CInt(Trim(t3.Text))
    
        Try
          con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\WebSite\database2\name.mdb;")
          con.Open()
          str = "INSERT INTO details VALUES(@t1,@t2,@t3)"
          com = New OleDbCommand(str, con)
          com.Parameters.AddWithValue("@t1", strt1)
          com.Parameters.AddWithValue("@t2", strt2)
          com.Parameters.AddWithValue("@t3", intt3)
          i = com.ExecuteNonQuery()
          If i > 0 Then
            l1.Text = "one record added"
          End If
        Catch es As Exception
          l1.Text = es.Message
        Finally
          con.Close()
        End Try


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •