...

View Full Version : Run-time exception thrown when using the following code...



sage45
08-19-2008, 05:59 PM
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.



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

--------------------

<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

vinyl-junkie
08-20-2008, 02:46 AM
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:


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

or maybe:


str="insert into details values(" & t1.text & "," & t2.text & "," & t3.text & ")"

SWI03
08-28-2008, 08:57 AM
this is works if you did not figure it out



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum