473,394 Members | 1,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

UpdateCommand problem


I have a SQL Server table with in Indetity column (value auto
generated).

I have tried to write my own updatecommand code.

I can't get it to work.
An error says that says Sku and rid are invalid column names. I don't
know why.

I even modified the Updatecommand the a bare bones
"UPDATE dbo.test1 SET sku = @SKU"
At least this gave me a different error!
The error says error in Prepared statement
"@SKU(20) Update dbo.test1 SET sku = @SKU"

Can anyone help?

Thanks,
Stu

Public da As Data.SqlClient.SqlDataAdapter, ds As DataSet, conn As
Data.SqlClient.SqlConnection

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
da.Update(ds, "CustSKUDateSettings")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'Viaware_arc_testDataSet1.CustSKUDateSettings' table. You can move, or
remove it, as needed.
Dim conn As New Data.SqlClient.SqlConnection
conn.ConnectionString = "..."
ds = New DataSet
da = New Data.SqlClient.SqlDataAdapter
da.SelectCommand = New Data.SqlClient.SqlCommand
da.SelectCommand.Connection = conn
da.InsertCommand = New Data.SqlClient.SqlCommand
da.InsertCommand.Connection = conn
da.UpdateCommand = New Data.SqlClient.SqlCommand
da.UpdateCommand.Connection = conn

da.SelectCommand.CommandText = "Select rid, custnum, sku,
search_date_type, date_range, date_sort_order, days_to_start,
days_to_end from CustSKUDateSettings"
da.Fill(ds, "CustSKUDateSettings")
DataGridView1.DataSource = ds.Tables("CustSKUDateSettings")
da.UpdateCommand.CommandText = " UPDATE dbo.test1 " & _
"SET sku = @SKU, " & _
"WHERE rid = @rid " & _
"CustNum = @CustNum, " &
_
"search_date_type =
@search_date_type," & _
"date_range =
@date_range," & _
"date_sort_order =
@date_sort_order," & _
"days_to_start =
@days_to_start," & _
"days_to_end =
@days_to_end " & _
da.UpdateCommand.CommandType = System.Data.CommandType.Text
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@rid", System.Data.SqlDbType.Int, 4,
"rid"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@SKU", System.Data.SqlDbType.Char,
20, "dbo.test1.sku"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@CustNum",
System.Data.SqlDbType.[Char], 15, "CustNum"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@search_date_t ype",
System.Data.SqlDbType.[Char], 1, "search_date_type"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@date_range",
System.Data.SqlDbType.[Char], 1, "date_range"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@date_sort_ord er",
System.Data.SqlDbType.[Char], 1, "date_sort_order"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@days_to_start ",
System.Data.SqlDbType.Int, 4, "days_to_start"))
da.UpdateCommand.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@days_to_end",
System.Data.SqlDbType.Int, 4, "days_to_end"))

*** Sent via Developersdex http://www.developersdex.com ***
Jul 1 '08 #1
0 932

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark | last post by:
Hi, I have a datalist that I use to display and edit records to a user. Datalist shown below; visual basic code:-----------------------------------------------------------------------...
1
by: niki | last post by:
Hello. I have a problem with custom columns inside the datagrid. I've set up a datagrid that populates from a database; I can edit the datagrid values and update the db, so that's ok. (btw, it's...
3
by: Jim in Arizona | last post by:
I'm doing my best to learn ASPNET from a book devoted to ASPNET 1.0. So far, I haven't run into any problems, until now. This is a simple page that should just show the sql strings created by the...
5
by: Peter W Johnson | last post by:
Hi Guys, I am having problems getting the following code to update an Access table. I get the following error:- An unhandled exception of type 'System.NullReferenceException' occurred in...
2
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
5
by: wandii | last post by:
Hi, I am trying to update the customer table by using the updatecommd, please see below, however, when it runs it does not fire the update statement. I ran the sql profiler and the only...
1
by: Rich | last post by:
Hello, I can update a dataset from my client app using a dataAdapter.Updatecommand when I add parameter values outside of the param declaration. But If I add the param values inline with the...
6
by: Rich | last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn) dim tblx As New DataTable da.Fill(tblx) '--works OK up to this point da.UpdateCommand = New SqlCommand da.UpdateCommand.Connection =...
0
by: Giovanni | last post by:
Hi, I'm new in vs2k8 and I'm trying to build up an ASP application that uses a DB. Situation: 2 tables related by a key (pk->fk). A Gridview on a web page that show me the 2 tables join query's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.