Dovberman
asked on
I need help with a SQL Insert staement with paramaters.
I need help with a SQL Insert staement with paramaters. The insert is called from a button on an ASP.NET page.
This is what I have:
Protected Sub btnNewQuoteHist_Click(ByVa l sender As Object, _
ByVal e As System.EventArgs) Handles btnNewQuoteHist.Click
Dim conStockSelector As SqlConnection
Dim strConnection As String = "Data Source=BURCEL05;Initial Catalog=StockSelectSQL;" _
& "Integrated Security=SSPI"
lblFileDate.Text = Me.calQuoteDate.SelectedDa te
conStockSelector = New SqlConnection(strConnectio n)
conStockSelector.Open()
Dim strInsert As String
strInsert = "INSERT INTO DownLoadHistory " _
& " VALUES (@DL_FileName,@DL_Date,Mar ketID,@DL_ Appended); "
Dim cmdSQL As SqlCommand = New SqlCommand(strInsert, conStockSelector)
cmdSQL.CommandText = strInsert
cmdSQL.Parameters.Add("@DL _FileName" , Data.SqlDbType.NVarChar).V alue = "ABC.txt"
cmdSQL.Parameters.Add("@DL _Date", Data.SqlDbType.DateTime).V alue = calQuoteDate.SelectedDate
cmdSQL.Parameters.Add("@Ma rketID", Data.SqlDbType.SmallInt).V alue = 2
cmdSQL.Parameters.Add("@DL _Appended" , Data.SqlDbType.Bit).Value = 0
cmdSQL.ExecuteNonQuery()
'Error The name "MarketID" is not permitted in this context
'Column names are not permitted
conStockSelector.Close()
I just need a hint on one of the Parameters.Add variables.
Thanks,
This is what I have:
Protected Sub btnNewQuoteHist_Click(ByVa
ByVal e As System.EventArgs) Handles btnNewQuoteHist.Click
Dim conStockSelector As SqlConnection
Dim strConnection As String = "Data Source=BURCEL05;Initial Catalog=StockSelectSQL;" _
& "Integrated Security=SSPI"
lblFileDate.Text = Me.calQuoteDate.SelectedDa
conStockSelector = New SqlConnection(strConnectio
conStockSelector.Open()
Dim strInsert As String
strInsert = "INSERT INTO DownLoadHistory " _
& " VALUES (@DL_FileName,@DL_Date,Mar
Dim cmdSQL As SqlCommand = New SqlCommand(strInsert, conStockSelector)
cmdSQL.CommandText = strInsert
cmdSQL.Parameters.Add("@DL
cmdSQL.Parameters.Add("@DL
cmdSQL.Parameters.Add("@Ma
cmdSQL.Parameters.Add("@DL
cmdSQL.ExecuteNonQuery()
'Error The name "MarketID" is not permitted in this context
'Column names are not permitted
conStockSelector.Close()
I just need a hint on one of the Parameters.Add variables.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
TimCottee
How simple. I wondered why only MarketID was the error source. I guess I should not have gotten up at 2 AM to work on this.
Thanks,
How simple. I wondered why only MarketID was the error source. I guess I should not have gotten up at 2 AM to work on this.
Thanks,
Always a bad idea to work at 2am. There are far better things to be doing at that time of day, not least sleeping!
replaces the "@" with ":"
strInsert = "INSERT INTO DownLoadHistory " _ & "VALUES :DL_FileName, :DL_Date, :MarketID, :DL_Appended)"
cmdSQL.Parameters.Add("DL_
cmdSQL.Parameters.Add("DL_
cmdSQL.Parameters.Add("Mar
cmdSQL.Parameters.Add("DL_