Showing posts with label dim. Show all posts
Showing posts with label dim. Show all posts

Friday, March 9, 2012

Insertparameters in code-behind

Hi,

How do I use insertparameters in code-behind? This is the code that I have

Dim insertSqlAs StringinsertSql ="INSERT INTO [xyzTable] ([x], [y]) VALUES (@.x, @.y)"SqlDataSource1.InsertCommand = insertSqlSqlDataSource1.InsertParameters.Add("@.x","124")SqlDataSource1.InsertParameters.Add("@.y","456")SqlDataSource1.Insert()

When I execute these line of code I get an error saying

"Must declare the variable '@.x'."

Please help

I assume your code block is under button click event:

Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click

Dim insertSqlAs String
insertSql ="INSERT INTO [xyzTable] ([x], [y]) VALUES (@.x, @.y)"
SqlDataSource1.InsertCommand = insertSql
SqlDataSource1.InsertParameters.Add("x","124")
SqlDataSource1.InsertParameters.Add("y","456")
SqlDataSource1.Insert()

End Sub

ADO.NET parameter and ASP.NET parameter are different. ADO.NET parameters always start with @. sign.

|||That simple -- just remove the @. sign. Thanks for your help

Sunday, February 19, 2012

Inserting pictures in DB - For VB programmers

Private conn As ADODB.Connection
Private rs As ADODB.Recordset

Private Sub ConnectToDB()

Dim strData As String

'Establish the connection.
Set conn = New ADODB.Connection
Call conn.Open("driver={SQL Server};server=srv_scgb\scg_sgbd;uid=tdela;pwd=pas sword;database=Mercure_tst")

'Open the recordset
Set rs = New ADODB.Recordset

'Make sure you don't retrieve any data !!!
Call rs.Open("Select * From Images Where FileName='0'", _
conn, _
adOpenKeyset, _
adLockOptimistic)

Call SaveToDB

Call rs.Close
Call conn.Close

Set rs = Nothing
Set conn = Nothing

End Sub

Private Sub SaveToDB()

Dim bytBLOB() As Byte
Dim strImagePath As String
Dim intNum As Integer

'Save the record
strImagePath = Trim("c:\windows\bureau\MyImage.bmp")

With rs
'Open the picture file
intNum = FreeFile
Open strImagePath For Binary As #intNum
ReDim bytBLOB(FileLen(strImagePath))

'Read data and close file
Get #intNum, , bytBLOB
Close #1

Call .AddNew
.Fields("FileName") = "The image title"
Call .Fields("Picture").AppendChunk(bytBLOB)
Call .Update
End With

End SubTable name >>> Images
Column 1 >>> FileName varchar(50)
Column2 >>> Pisture image(16)