[quoted text, click to view] zheetee@gmail.com wrote:
> Sub add_Click(sender As Object, e As EventArgs)
> head.text=SerialNumber1.text
>
>
There was no way for you to know it (except maybe by browsing through some
of the previous questions before posting yours - always a recommended
practice) , but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.
There are several issues with your code. Read on.
[quoted text, click to view] > 'msgBox SerialNumber
msgbox? In server-side code? Not good. :-)
[quoted text, click to view] >
> dim dbconn,sql,dbcomm,dbread
OK, you're not coding in vbscript anymore. This is VB.Net: a strongly-typed
language. Always declare your variables with appropriate data types:
dim varname As datatype
Also, VB.Net supports declaring and assigning values to variables in a
single line of code. So this:
[quoted text, click to view] > dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
> source=" & server.mappath("/db/equipment.mdb"))
should be this:
dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source=" & _
server.mappath("/db/equipment.mdb"))
[quoted text, click to view] > dbconn.Open()
>
>
> sql="INSERT INTO test (SerialNumber) VALUES (@SerialNumber1)"
The OLEDbCommand object does not support using named parameters. Instead,
use question marks for parameter markers:
dim sql as String="INSERT INTO test (SerialNumber) VALUES (?)"
[quoted text, click to view] > '(@SerialNumber1)"
> 'SerialNumber1.text=""
This:
[quoted text, click to view] > dbcomm=New OleDbCommand(sql,dbconn)
should be:
dim dbcomm As New OleDbCommand(sql,dbconn)
[quoted text, click to view] > dbread=dbcomm.ExecuteReader()
Your sql statement does not return records. Do not try and open a reader. Do
not use ExecuteReader. Use ExecuteNonQuery.
Also, you need to set the command type and create the Parameters collection,
like this (use the appropriate datatype for your serial number field - this
example uses integer.):
with dbcomm
.commandtype=CommandType.Text
.Parameters.Add("@SerialNum", OleDbType.Integer).Value = 239
end with
Try
dbcomm.ExecuteNonQuery
Catch ex as exception
'handle the error
Finally
dbcomm.dispose
dbconn.close
dbconn.dispose
End Try
[quoted text, click to view] > 'portable.DataSource=dbread
> 'portable.DataBind()
> dbread.Close()
> dbconn.Close()
>
> End Sub
>
Follow up in the aspnet group.
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"