T
te_butts
Using VS2005, and SQL 2005 Express.
Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifier)(newid()) - So it adds
new UI when new row is inserted.
- Second column called ItemCode(NVarChar)
VB Form
DataGridView called ProductsDGV
When i created the ProductsDGV it created the BindingDataSource,
TableAdapter, and DataSet. As I went through the wizard it says that SELECT,
INSERT, UPDATE, AND DELETE commands are also created.
Problem:
When i have buttons to INSERT, UPDATE, AND DELETE, the database changes
perfectly. When i add the same code that i have for the INSERT button to an
event of the ProductsDGV like RowLeave i get the error "The parameterized
query ('@ProductID ...)' which was not supplied.
Here is my code in the RowLeave Event of the ProductsDGV:
Dim cnxn As New Data.SqlClient.SqlConnection
Dim cmd As New Data.SqlClient.SqlCommand
cnxn.ConnectionString = "Data Source=ADDLMNARWP13\SQLEXPRESS;Initial
Catalog=myDatabase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn
With cmd.Parameters
.Add(New Data.SqlClient.SqlParameter("ProductID", ProductsID))
.Add(New Data.SqlClient.SqlParameter("ItemCode",
SqlDbType.NVarChar))
.Add(New Data.SqlClient.SqlParameter("Description",
SqlDbType.NVarChar))
.Add(New Data.SqlClient.SqlParameter("Cost", SqlDbType.NVarChar))
End With
cmd.CommandText = "INSERT INTO
dbo.Products(ProductsID,ItemCode,Description,Cost) VALUES
(@ProductsID,@ItemCode,@Description,@Cost)"
cmd.ExecuteNonQuery()
cnxn.Close()
Me.ProductsTableAdapter.Fill(Me.ProductsDataSet.Products)
Thanks for the help!
Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifier)(newid()) - So it adds
new UI when new row is inserted.
- Second column called ItemCode(NVarChar)
VB Form
DataGridView called ProductsDGV
When i created the ProductsDGV it created the BindingDataSource,
TableAdapter, and DataSet. As I went through the wizard it says that SELECT,
INSERT, UPDATE, AND DELETE commands are also created.
Problem:
When i have buttons to INSERT, UPDATE, AND DELETE, the database changes
perfectly. When i add the same code that i have for the INSERT button to an
event of the ProductsDGV like RowLeave i get the error "The parameterized
query ('@ProductID ...)' which was not supplied.
Here is my code in the RowLeave Event of the ProductsDGV:
Dim cnxn As New Data.SqlClient.SqlConnection
Dim cmd As New Data.SqlClient.SqlCommand
cnxn.ConnectionString = "Data Source=ADDLMNARWP13\SQLEXPRESS;Initial
Catalog=myDatabase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn
With cmd.Parameters
.Add(New Data.SqlClient.SqlParameter("ProductID", ProductsID))
.Add(New Data.SqlClient.SqlParameter("ItemCode",
SqlDbType.NVarChar))
.Add(New Data.SqlClient.SqlParameter("Description",
SqlDbType.NVarChar))
.Add(New Data.SqlClient.SqlParameter("Cost", SqlDbType.NVarChar))
End With
cmd.CommandText = "INSERT INTO
dbo.Products(ProductsID,ItemCode,Description,Cost) VALUES
(@ProductsID,@ItemCode,@Description,@Cost)"
cmd.ExecuteNonQuery()
cnxn.Close()
Me.ProductsTableAdapter.Fill(Me.ProductsDataSet.Products)
Thanks for the help!