Data Access Issues

J

Jerry Camel

I'm trying to update a table on a SQL Server from a web page. I'm not having any problems reading the data, but I can't seem to update it. From the code below can someone please tell me what I'm missing? I'm sure I've kludged it up a bit with all my attempts. Thanks.

Dim sFileName As String
sFileName = Now.Millisecond & Now.Second & Now.Minute & Now.Hour & Now.Year & Now.Month & Now.Day

Dim sqlCnxn As New SqlConnection("user id=SomeUser;password=Pswd;data source=DATASERVER")
Dim daFiles As New SqlDataAdapter("SELECT * FROM FD_Files", sqlCnxn)
Dim dsFiles As New DataSet()
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(daFiles)

daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables(0).NewRow
dr("FileName") = Path.GetFileName(txtFile.PostedFile.FileName)
dr("ExpireTime") = Now.AddHours(24)
dr("PostedBy") = Session("UserAlias")
dr("HashName") = sFileName
dr("FileSize") = txtFile.PostedFile.ContentLength / 1024
dr("Description") = txtDescription.Text
dsFiles.Tables(0).Rows.Add(dr)
dsFiles.AcceptChanges()
daFiles.Update(dsFiles, "FD_Files")
 
J

Jerry Camel

It helps if you generate the SQL Commands after you add the rows to the table... I knew it had to be an easy fix.

Jerry
I'm trying to update a table on a SQL Server from a web page. I'm not having any problems reading the data, but I can't seem to update it. From the code below can someone please tell me what I'm missing? I'm sure I've kludged it up a bit with all my attempts. Thanks.

Dim sFileName As String
sFileName = Now.Millisecond & Now.Second & Now.Minute & Now.Hour & Now.Year & Now.Month & Now.Day

Dim sqlCnxn As New SqlConnection("user id=SomeUser;password=Pswd;data source=DATASERVER")
Dim daFiles As New SqlDataAdapter("SELECT * FROM FD_Files", sqlCnxn)
Dim dsFiles As New DataSet()
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(daFiles)

daFiles.Fill(dsFiles, "FD_Files")
Dim dr As DataRow = dsFiles.Tables(0).NewRow
dr("FileName") = Path.GetFileName(txtFile.PostedFile.FileName)
dr("ExpireTime") = Now.AddHours(24)
dr("PostedBy") = Session("UserAlias")
dr("HashName") = sFileName
dr("FileSize") = txtFile.PostedFile.ContentLength / 1024
dr("Description") = txtDescription.Text
dsFiles.Tables(0).Rows.Add(dr)
dsFiles.AcceptChanges()
daFiles.Update(dsFiles, "FD_Files")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top