Showing posts with label record. Show all posts
Showing posts with label record. Show all posts

Saturday, March 24, 2012

Please help : System.Data.OleDb.OleDbException: Syntax error in IN

Hello All,

I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message,

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

And the line it shows in red is

cmd.ExecuteNonQuery()

I have pasted the entire code here. Can someone please give me some clue as what could be wrong. The SQL string looks fine because I pasted the resulting SQL in to MS Access. When I ran the Insert query, it properly added the record in the Access DB.

Thanks,

Joe

<%@dotnet.itags.org. Page Language="VB" Debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source='E:/Inetpub/databases/investors.mdb'")
objConn.Open()

'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again.")
Response.Write("</A>")
Response.End()
End If

bolAlreadyExists = False

Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()

Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) = 0) Then
Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop

objDataReader.Close()

If Not bolAlreadyExists Then

Dim Email, passwd, first_name, last_name, company, street_address, address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor, RemoteIP
Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")

Dim MySQL as String

MySQL = "INSERT INTO Results(email, password, first_name, last_name, company, street_address, address2, city, state, country, postal, phone, mobile, AddDate, Inv, RemoteIP)" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_name & "', '" & company & "', '" & street_address & "', '" & address2 & "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '" & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "', '" & RemoteIP & "')"

Dim cmd as New OleDBCommand (MySQL, objConn)

cmd.ExecuteNonQuery ()
End if

objConn = Nothing
objConn.Close()

%I believe 'password' is a keyword - but it is also your column name. Try
putting [ and ] around the column name.

Alsok you shouldn't just concatenate strings together given to you by the
user. They could easily put in malicious SQL for one of those values. I
would recommend using parameters.

"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> Hello All,
> I am trying to insert a record in the MS Access DB and for some reason I
cannot get rid of error message,
> System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> And the line it shows in red is
> cmd.ExecuteNonQuery()
> I have pasted the entire code here. Can someone please give me some clue
as what could be wrong. The SQL string looks fine because I pasted the
resulting SQL in to MS Access. When I ran the Insert query, it properly
added the record in the Access DB.
> Thanks,
> Joe
>
> <%@. Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
> <%@. Import Namespace="System.Data.OleDb" %>
> <%@. Import Namespace="System.Data" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <%
> 'Open up a connection to Access database
> 'Using a DSN connection.
> Dim bolfFound, strUsername, bolAlreadyExists
> Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source='E:/Inetpub/databases/investors.mdb'")
> objConn.Open()
> 'check state
> If Session("strAdmin") <> "test" Then
> objConn.Close()
> objConn = Nothing
> Response.Write("<A HREF=index.aspx'>")
> Response.Write("Sorry, looks like your session timed out, please login
again.")
> Response.Write("</A>")
> Response.End()
> End If
> bolAlreadyExists = False
> Dim objDataReader as OledbDataReader
> Dim objCommand as New OledbCommand("Select * From Results", objConn)
> objDataReader = objCommand.ExecuteReader()
> Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
= 0) Then
> Response.Redirect("record_exists.aspx")
> bolAlreadyExists = True
> End If
> Loop
> objDataReader.Close()
> If Not bolAlreadyExists Then
> Dim Email, passwd, first_name, last_name, company, street_address,
address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
RemoteIP
> Email = Request.Form("Email")
> passwd = Request.Form("password")
> first_name = Request.Form("first_name")
> last_name = Request.Form("last_name")
> company = Request.Form("company")
> street_address = Request.Form("street_address")
> address2 = Request.Form("address2")
> city = Request.Form("city")
> prov = Request.Form("state")
> country = Request.Form("country")
> postal = Request.Form("postal")
> phone = Request.Form("phone")
> mobilePhone = Request.Form("mobile")
> AddDate = Now
> Inv = "Yes"
> RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> Dim MySQL as String
> MySQL = "INSERT INTO Results(email, password, first_name, last_name,
company, street_address, address2, city, state, country, postal, phone,
mobile, AddDate, Inv, RemoteIP)" & _
> " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"
> Dim cmd as New OleDBCommand (MySQL, objConn)
> cmd.ExecuteNonQuery ()
> End if
> objConn = Nothing
> objConn.Close()
> %
Yep..that got me a few times. Also Joe, be careful of using Date as a column name as well, I know you didn't use it here but I had to find out the hard way. It will cause the same type of error. The Jet Provider is picky about those kinds of words

"Marina" wrote:

> I believe 'password' is a keyword - but it is also your column name. Try
> putting [ and ] around the column name.
> Alsok you shouldn't just concatenate strings together given to you by the
> user. They could easily put in malicious SQL for one of those values. I
> would recommend using parameters.
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> > Hello All,
> > I am trying to insert a record in the MS Access DB and for some reason I
> cannot get rid of error message,
> > System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> > And the line it shows in red is
> > cmd.ExecuteNonQuery()
> > I have pasted the entire code here. Can someone please give me some clue
> as what could be wrong. The SQL string looks fine because I pasted the
> resulting SQL in to MS Access. When I ran the Insert query, it properly
> added the record in the Access DB.
> > Thanks,
> > Joe
> > <%@. Page Language="VB" Debug="true" ContentType="text/html"
> ResponseEncoding="iso-8859-1" %>
> > <%@. Import Namespace="System.Data.OleDb" %>
> > <%@. Import Namespace="System.Data" %>
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> > <%
> > 'Open up a connection to Access database
> > 'Using a DSN connection.
> > Dim bolfFound, strUsername, bolAlreadyExists
> > Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
> source='E:/Inetpub/databases/investors.mdb'")
> > objConn.Open()
> > 'check state
> > If Session("strAdmin") <> "test" Then
> > objConn.Close()
> > objConn = Nothing
> > Response.Write("<A HREF=index.aspx'>")
> > Response.Write("Sorry, looks like your session timed out, please login
> again.")
> > Response.Write("</A>")
> > Response.End()
> > End If
> > bolAlreadyExists = False
> > Dim objDataReader as OledbDataReader
> > Dim objCommand as New OledbCommand("Select * From Results", objConn)
> > objDataReader = objCommand.ExecuteReader()
> > Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> > If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
> = 0) Then
> > Response.Redirect("record_exists.aspx")
> > bolAlreadyExists = True
> > End If
> > Loop
> > objDataReader.Close()
> > If Not bolAlreadyExists Then
> > Dim Email, passwd, first_name, last_name, company, street_address,
> address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
> RemoteIP
> > Email = Request.Form("Email")
> > passwd = Request.Form("password")
> > first_name = Request.Form("first_name")
> > last_name = Request.Form("last_name")
> > company = Request.Form("company")
> > street_address = Request.Form("street_address")
> > address2 = Request.Form("address2")
> > city = Request.Form("city")
> > prov = Request.Form("state")
> > country = Request.Form("country")
> > postal = Request.Form("postal")
> > phone = Request.Form("phone")
> > mobilePhone = Request.Form("mobile")
> > AddDate = Now
> > Inv = "Yes"
> > RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> > Dim MySQL as String
> > MySQL = "INSERT INTO Results(email, password, first_name, last_name,
> company, street_address, address2, city, state, country, postal, phone,
> mobile, AddDate, Inv, RemoteIP)" & _
> > " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
> last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
> "', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
> & phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
> '" & RemoteIP & "')"
> > Dim cmd as New OleDBCommand (MySQL, objConn)
> > cmd.ExecuteNonQuery ()
> > End if
> > objConn = Nothing
> > objConn.Close()
> > %>
>

Please help : System.Data.OleDb.OleDbException: Syntax error in IN

Hello All,
I am trying to insert a record in the MS Access DB and for some reason I can
not get rid of error message,
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
And the line it shows in red is
cmd.ExecuteNonQuery()
I have pasted the entire code here. Can someone please give me some clue as
what could be wrong. The SQL string looks fine because I pasted the result
ing SQL in to MS Access. When I ran the Insert query, it properly added the
record in the Access DB.
Thanks,
Joe
<%@dotnet.itags.org. Page Language="VB" Debug="true" ContentType="text/html" ResponseEncodin
g="iso-8859-1" %>
<%@dotnet.itags.org. Import Namespace="System.Data.OleDb" %>
<%@dotnet.itags.org. Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w
3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
'Open up a connection to Access database
'Using a DSN connection.
Dim bolfFound, strUsername, bolAlreadyExists
Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data so
urce='E:/Inetpub/databases/investors.mdb'")
objConn.Open()
'check state
If Session("strAdmin") <> "test" Then
objConn.Close()
objConn = Nothing
Response.Write("<A HREF=index.aspx'>")
Response.Write("Sorry, looks like your session timed out, please login again
.")
Response.Write("</A>")
Response.End()
End If
bolAlreadyExists = False
Dim objDataReader as OledbDataReader
Dim objCommand as New OledbCommand("Select * From Results", objConn)
objDataReader = objCommand.ExecuteReader()
Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare) =
0) Then
Response.Redirect("record_exists.aspx")
bolAlreadyExists = True
End If
Loop
objDataReader.Close()
If Not bolAlreadyExists Then
Dim Email, passwd, first_name, last_name, company, street_address, address2,
city, prov, country, postal, phone, mobilePhone, AddDate,Investor, RemoteIP
Email = Request.Form("Email")
passwd = Request.Form("password")
first_name = Request.Form("first_name")
last_name = Request.Form("last_name")
company = Request.Form("company")
street_address = Request.Form("street_address")
address2 = Request.Form("address2")
city = Request.Form("city")
prov = Request.Form("state")
country = Request.Form("country")
postal = Request.Form("postal")
phone = Request.Form("phone")
mobilePhone = Request.Form("mobile")
AddDate = Now
Inv = "Yes"
RemoteIP = Request.ServerVariables("REMOTE_ADDR")
Dim MySQL as String
MySQL = "INSERT INTO Results(email, password, first_name, last_name, company
, street_address, address2, city, state, country, postal, phone, mobile, Add
Date, Inv, RemoteIP)" & _
" VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" & last_
name & "', '" & company & "', '" & street_address & "', '" & address2 & "',
'" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '" & ph
one & "', '" & mobilePho
ne & "', '" & AddDate & "', '" & Investor & "', '" & RemoteIP & "')"
Dim cmd as New OleDBCommand (MySQL, objConn)
cmd.ExecuteNonQuery ()
End if
objConn = Nothing
objConn.Close()
%>I believe 'password' is a keyword - but it is also your column name. Try
putting [ and ] around the column name.
Alsok you shouldn't just concatenate strings together given to you by the
user. They could easily put in malicious SQL for one of those values. I
would recommend using parameters.
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:46E04C27-2E28-4AF8-B67B-B4492B7F2298@.microsoft.com...
> Hello All,
> I am trying to insert a record in the MS Access DB and for some reason I
cannot get rid of error message,
> System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
> And the line it shows in red is
> cmd.ExecuteNonQuery()
> I have pasted the entire code here. Can someone please give me some clue
as what could be wrong. The SQL string looks fine because I pasted the
resulting SQL in to MS Access. When I ran the Insert query, it properly
added the record in the Access DB.
> Thanks,
> Joe
>
> <%@. Page Language="VB" Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
> <%@. Import Namespace="System.Data.OleDb" %>
> <%@. Import Namespace="System.Data" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> <%
> 'Open up a connection to Access database
> 'Using a DSN connection.
> Dim bolfFound, strUsername, bolAlreadyExists
> Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data
source='E:/Inetpub/databases/investors.mdb'")
> objConn.Open()
> 'check state
> If Session("strAdmin") <> "test" Then
> objConn.Close()
> objConn = Nothing
> Response.Write("<A HREF=index.aspx'>")
> Response.Write("Sorry, looks like your session timed out, please login
again.")
> Response.Write("</A>")
> Response.End()
> End If
> bolAlreadyExists = False
> Dim objDataReader as OledbDataReader
> Dim objCommand as New OledbCommand("Select * From Results", objConn)
> objDataReader = objCommand.ExecuteReader()
> Do While Not (objDataReader.Read()= False OR bolAlreadyExists)
> If (StrComp(objDataReader("Email"), Request.Form("Email"), vbTextCompare)
= 0) Then
> Response.Redirect("record_exists.aspx")
> bolAlreadyExists = True
> End If
> Loop
> objDataReader.Close()
> If Not bolAlreadyExists Then
> Dim Email, passwd, first_name, last_name, company, street_address,
address2, city, prov, country, postal, phone, mobilePhone, AddDate,Investor,
RemoteIP
> Email = Request.Form("Email")
> passwd = Request.Form("password")
> first_name = Request.Form("first_name")
> last_name = Request.Form("last_name")
> company = Request.Form("company")
> street_address = Request.Form("street_address")
> address2 = Request.Form("address2")
> city = Request.Form("city")
> prov = Request.Form("state")
> country = Request.Form("country")
> postal = Request.Form("postal")
> phone = Request.Form("phone")
> mobilePhone = Request.Form("mobile")
> AddDate = Now
> Inv = "Yes"
> RemoteIP = Request.ServerVariables("REMOTE_ADDR")
> Dim MySQL as String
> MySQL = "INSERT INTO Results(email, password, first_name, last_name,
company, street_address, address2, city, state, country, postal, phone,
mobile, AddDate, Inv, RemoteIP)" & _
> " VALUES('" & Email & "', '" & passwd & "', '" & first_name & "', '" &
last_name & "', '" & company & "', '" & street_address & "', '" & address2 &
"', '" & city & "', '" & prov & "', '" & country & "', '" & postal & "', '"
& phone & "', '" & mobilePhone & "', '" & AddDate & "', '" & Investor & "',
'" & RemoteIP & "')"
> Dim cmd as New OleDBCommand (MySQL, objConn)
> cmd.ExecuteNonQuery ()
> End if
> objConn = Nothing
> objConn.Close()
> %>
>

PLEASE HELP ASP.NET PROBLEM

Dear All,

I have encountered a very strange problem with DataBinding a repeater.

1. I have a DataTable that has 100 record (3 columns with number only and
the records count is also confirmed)
2.I have created a proper Repeater
3. The Repeater has a databinding with the datatable
4.When I databind() the repeater, only some of the records get rendered and
the remaining aspx file ends up incomplete! it is as though the databinding
breaks at some point resulting the page not being parsed correctly.
5. I am using .NET 1.1 with spk

Has anyone ever seen something like this?Can you provide more info or where the error is existing in your code.
Patrick

"Yet another C# coder" <gevik@.hotmail.com> wrote in message
news:O$9ScPKuFHA.3236@.TK2MSFTNGP14.phx.gbl...
> Dear All,
> I have encountered a very strange problem with DataBinding a repeater.
> 1. I have a DataTable that has 100 record (3 columns with number only and
> the records count is also confirmed)
> 2.I have created a proper Repeater
> 3. The Repeater has a databinding with the datatable
> 4.When I databind() the repeater, only some of the records get rendered
and
> the remaining aspx file ends up incomplete! it is as though the
databinding
> breaks at some point resulting the page not being parsed correctly.
> 5. I am using .NET 1.1 with spk
> Has anyone ever seen something like this?

PLEASE HELP ASP.NET PROBLEM

Dear All,
I have encountered a very strange problem with DataBinding a repeater.
1. I have a DataTable that has 100 record (3 columns with number only and
the records count is also confirmed)
2.I have created a proper Repeater
3. The Repeater has a databinding with the datatable
4.When I databind() the repeater, only some of the records get rendered and
the remaining aspx file ends up incomplete! it is as though the databinding
breaks at some point resulting the page not being parsed correctly.
5. I am using .NET 1.1 with spk
Has anyone ever seen something like this?Can you provide more info or where the error is existing in your code.
Patrick
"Yet another C# coder" <gevik@.hotmail.com> wrote in message
news:O$9ScPKuFHA.3236@.TK2MSFTNGP14.phx.gbl...
> Dear All,
> I have encountered a very strange problem with DataBinding a repeater.
> 1. I have a DataTable that has 100 record (3 columns with number only and
> the records count is also confirmed)
> 2.I have created a proper Repeater
> 3. The Repeater has a databinding with the datatable
> 4.When I databind() the repeater, only some of the records get rendered
and
> the remaining aspx file ends up incomplete! it is as though the
databinding
> breaks at some point resulting the page not being parsed correctly.
> 5. I am using .NET 1.1 with spk
> Has anyone ever seen something like this?
>

Please help how to call stored procedure from asp.net code

Please help, first time trying to use the stored procedure.

Can you please modify my code below which is in asp.net to insert the record's in table(tbl_labels), i don't have not problem in inserting records, but i want to use my stored procedure to insert the record. Please help I never used a stored procedure.

**********


CREATE PROCEDURE sp_insert_label
(
@dotnet.itags.org.engl nvarchar,
@dotnet.itags.org.espl nvarchar,
@dotnet.itags.org.frlbl nvarchar,
@dotnet.itags.org.gerlbl nvarchar
)
AS
INSERT INTO tbl_labels
(
eng_lbl,
esp_lbl,
fr_lbl,
ger_lbl
)
VALUES
(
@dotnet.itags.org.engl,
@dotnet.itags.org.espl,
@dotnet.itags.org.frlbl,
@dotnet.itags.org.gerlbl
)
GO

********** the following is my asp.net code***

Sub Addlabel_Click(Sender As Object, E As EventArgs)
Page.Validate()
If Not Page.IsValid
Return
End If

Dim DS As DataSet
Dim MyCommand As SqlCommand
Dim InsertCmd As String = "insert into tbl_labels(eng_lbl, esp_lbl, " & _
"fr_lbl, ger_lbl) values " & _
"(@dotnet.itags.org.engl, @dotnet.itags.org.espn, @dotnet.itags.org.fren, @dotnet.itags.org.german)"

MyCommand = New SqlCommand(InsertCmd, MyConnection)

MyCommand.Parameters.Add( "@dotnet.itags.org.engl", eng_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.espn", esp_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.fren", fr_lbl.Value )
MyCommand.Parameters.Add( "@dotnet.itags.org.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try
MyCommand.ExecuteNonQuery()
Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()
ger_lbl.Value = ""
fr_lbl.Value = ""
esp_lbl.Value = ""
eng_lbl.Value = ""

Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the " & _
"same primary key"
Else
Message.InnerHtml = "ERROR: Could not add record, please ensure " & _
"the fields are correctly filled out"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()
BindGrid()
End Sub

Hi,

Dim DS As DataSet

Dim MyCommand As SqlCommand

Dim pmEngl, pmEspn, pmFren, pmGerman As SqlParameter = New SqlParameter()

MyCommand = New SqlCommand("sp_insert_label", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure;

pmEngl = MyCommand.Parameters.Add( "@.engl", eng_lbl.Value )

pmEspn = MyCommand.Parameters.Add( "@.espn", esp_lbl.Value )

pmFren = MyCommand.Parameters.Add( "@.fren", fr_lbl.Value )

pmGerman = MyCommand.Parameters.Add( "@.german", ger_lbl.Value )

MyCommand.Connection.Open()

Try

MyCommand.ExecuteNonQuery()

Message.InnerHtml = "Label Added Successfully to Dictionary.<br>" '& InsertCmd.ToString()

ger_lbl.Value = ""

fr_lbl.Value = ""

esp_lbl.Value = ""

eng_lbl.Value = ""

hope it helps.
You can add parameters to stored procedures in different ways:

One of the useful way is:

myCommand.Parameters.Add(new SqlParameters("@.ParameterName",SqlDbType.nvarchar,50));
Thank you very much for your help Harish.

Wednesday, March 21, 2012

please help me on multiple update recordset

when i select 2 records to update from checkbox, it only updated 1 record. can anyone help me?

code
====

<%
if request("deleted")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause from Users where id IN ("&request("deleted")&")"
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="1"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script
=======================================================Instead of if ... then go for

while not rs.eof
rs("pause")="1"
rs.update
rs.movenext
wend

:))
Devendra.
Thanks cdnaik
I't works.
:)

Friday, March 16, 2012

Please Help me understand..

I want to create a page that pulls a specific record from a database based on the value passed from a Request.QueryString. If the value is not in the string then it uses a default value of 1(one). Here is what I have so far:

' Determine if a Content ID has been passed in the query string
' If so use it as a variable in our SQL string to grab content for the page
' Httpcontext.Request.Querystring("Content_id")

Sub BindHomeBodyData() ' GRAB CONTENT *************************

Const strSQL as String = "SELECT * FROM Content WHERE Content_ID = " & Httpcontext.Request.Querystring("Content_id")
Dim myCommand as New SqlCommand(strSQL, myConnection)
Dim myDA as New SqlDataAdapter()
myDA.SelectCommand = myCommand
Dim myDS as New DataSet()
myDA.Fill(myDS)
dlHomeBodyData.DataSource = myDS
dlHomeBodyData.DataBind()

End SubNot tested:

Dim Content_ID As Integer = 1

If Not IsNull(Request.QueryString("Content_id")) Then
Dim myRegEx As New RegEx("[^0-9]"), sContent As String = myRegEx.Replace(Request.QueryString("Content_id"), "")

If sContent <> "" Then
Content_ID = CInt(sContent)
End If
End If


to take what you have given me and place it into what I have. Sorry I am an extreme newbie. Here is what I have is there any way you could educate me here and show me how to write this out according to my example. Thanks a lot I appreciate it.

Sub BindHomeBodyData() ' GRAB CONTENT *************************

Const strSQL as String = "SELECT * FROM Content WHERE Content_ID = " & Httpcontext.Request.Querystring("Content_id")
Dim myCommand as New SqlCommand(strSQL, myConnection)
Dim myDA as New SqlDataAdapter()
myDA.SelectCommand = myCommand
Dim myDS as New DataSet()
myDA.Fill(myDS)
dlHomeBodyData.DataSource = myDS
dlHomeBodyData.DataBind()

End Sub

Please help me with this simple line of code.

Hello,
i am creating an ASP.net / VB web site with Dreamweaver MX 2004.
I have a form and a "Insert Record Behavior" to insert the form values in
the database.
Dreamweaver puts this code in the end of the form:
..
<input type="hidden" name="MM_insert" value="myForm"> (1)
</form>
The form is in a Multipanel. So when i first click the "Next" button the
form values are inserted in the database.
I want the form values to be inserted in the database only when the "Finish"
button is pressed.
I have the code which detects when the "Finish" button is pressed. All i
need is to know how to give the order not in (1) but inside the following
code:
Sub btnFinish_Click( s As Object, e As EventArgs )
End Sub
I am on this since today morning but until know i have no idea of how to do
this. Please help me. I tryied and looked for every options.
Thank You,
MiguelI believe what you are asking is "how do I code for inserting a record when
the finish button is clicked"...is that about right?
If this is what you are asking, you have not provided enough information, su
ch as what is the source file you are wanting to update.
You will need a Connection Object, which typically come in 3 flavors (ODBC,
OLEDB, or SQL)
You will need a connection string to properly build your command object. Th
ere are places on the web which provided examples of connection strings to t
he 3 flavors noted above. Seach on ConnectionString or OLEDB Connections
You will need a command Object, again, these come in the same 3 flavors.
To properly build the Command ogject, you will need to Connection Object dis
cussed above and your query - Something line "Insert into MyDatabaseName Val
ues( MyValue1,...MyLastValue) .
Once you have all of that in-place, you will then need to open the connectio
n.
Then you will use the "ExecuteNonQuery" method of the command object, which
will invoke your query.
If you have never created a connection to your database/file or every writte
n a query, you have a lot of studying to do.

Please help me with this simple line of code.

Hello,

i am creating an ASP.net / VB web site with Dreamweaver MX 2004.

I have a form and a "Insert Record Behavior" to insert the form values in
the database.

Dreamweaver puts this code in the end of the form:
...
<input type="hidden" name="MM_insert" value="myForm"> (1)
</form
The form is in a Multipanel. So when i first click the "Next" button the
form values are inserted in the database.
I want the form values to be inserted in the database only when the "Finish"
button is pressed.

I have the code which detects when the "Finish" button is pressed. All i
need is to know how to give the order not in (1) but inside the following
code:

Sub btnFinish_Click( s As Object, e As EventArgs )
>> I want to give the order here.
End Sub

I am on this since today morning but until know i have no idea of how to do
this. Please help me. I tryied and looked for every options.

Thank You,
MiguelI believe what you are asking is "how do I code for inserting a record when the finish button is clicked"...is that about right?
If this is what you are asking, you have not provided enough information, such as what is the source file you are wanting to update.

You will need a Connection Object, which typically come in 3 flavors (ODBC, OLEDB, or SQL)
You will need a connection string to properly build your command object. There are places on the web which provided examples of connection strings to the 3 flavors noted above. Seach on ConnectionString or OLEDB Connections
You will need a command Object, again, these come in the same 3 flavors.
To properly build the Command ogject, you will need to Connection Object discussed above and your query - Something line "Insert into MyDatabaseName Values( MyValue1,...MyLastValue) .
Once you have all of that in-place, you will then need to open the connection.
Then you will use the "ExecuteNonQuery" method of the command object, which will invoke your query.

If you have never created a connection to your database/file or every written a query, you have a lot of studying to do.