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.Pr oducts)
Thanks for the help! 4 1656
Hi,
.Add(New Data.SqlClient.SqlParameter("@ProductID", ProductsID))
etc,
But why do you not simple use
\\\
Me.ProductTableAdapter.Update(Me.ProductsDataset.P roducts)
me.ProductsDataSet.Products.Clear
Me.ProductsTableAdapter.Fill(Me.ProductsDataSet.Pr oducts)
///
Cor
"te_butts" <te*****@discussions.microsoft.comschreef in bericht
news:96**********************************@microsof t.com...
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.Pr oducts)
Thanks for the help!
I have done that and i get different errors all over the place.
Here is what i did to fix the problem.
In the database:
Changed the ProductID to INT, and made Is Identity = yes.
Made ProductID a Primary Key.
Code:
Me.Validate()
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.ProductsDataSet. Products)
Deleted Productbindings, tableadapter, and dataset, remade them and all is
good in the world. Select, updating, and inserting works good, but delete is
not working yet.
"Cor Ligthert[MVP]" wrote:
Hi,
.Add(New Data.SqlClient.SqlParameter("@ProductID", ProductsID))
etc,
But why do you not simple use
\\\
Me.ProductTableAdapter.Update(Me.ProductsDataset.P roducts)
me.ProductsDataSet.Products.Clear
Me.ProductsTableAdapter.Fill(Me.ProductsDataSet.Pr oducts)
///
Cor
"te_butts" <te*****@discussions.microsoft.comschreef in bericht
news:96**********************************@microsof t.com...
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.Pr oducts)
Thanks for the help!
The wizard(s) provides a generic set of commands for your dataset. This
makes it fairly restricted - especially if you are binding the data. An
easier way to handle your situation is to define your own
sqlDataAdapter, Dataset, sqlCommands,... and then fill your dataset
-----------------------------------------
Imports System
Imports System.Data.SqlClient
Dim da As SqlDataAdapter, ds As Dataset, conn as SqlConnection
Private Sub Form1_Load(...)
conn = new sqlConnection
conn.ConnectionString = "..."
ds = New Dataset
da = new SqlDataAdapter
da.SelectCommand = New SqlCommand
da.SelectCommand.Connection = conn
da.InserCommand = New SqlCommand
da.InsertCommand.Connection = conn
da.UpdateCommand = New SqlCommand
da.UpdateCommand.Connection = conn
da.SelectCommand.CommandText = "Select * from your table"
da.Fill(ds,"tbl1")
datagridview1.DataSource = ds.Tables("tbl1")
da.UpdateCommand.CommandText = "Update Table1 Set fld1 = @p1, fld2 = @p2
fld3 = @p3,... Where ID = @ID"
da.UpdateCommand.Parameters.Add("@p1", SqlDBType.Varchar, 50, "fld1")
da.UpdateCommand.Parameters.Add("@p2", SqlDBType.Varchar, 50, "fld2")
...
End Sub
Private Sub datagridview1_CellValueChanged(ByVal sender As Object, ByVal
e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
datagridview1.CellValueChanged
Try
Dim strID As String =
datagridview1.Rows(e.RowIndex).Cells("ID").Value.T oString
Dim s1 As String = datagridview1.Columns(e.ColumnIndex).Name
Dim drF() As DataRow = ds.Tables("tbl1").Select("ID = " & strID)
Dim strArg As String =
datagridview1.Rows(e.RowIndex).Cells(e.ColumnIndex ).Value.ToString.ToUpp
er
datagridview1.Rows(e.RowIndex).Cells(e.ColumnIndex ).Value = strArg
For Each dr As DataRow In drF
dr.BeginEdit()
dr(e.ColumnIndex) =
dgrvInactiveDetail.Rows(e.RowIndex).Cells(e.Column Index).Value
dr.EndEdit()
Next
Application.DoEvents()
da.Update(ds, "tbl1")
End Sub
--------------------------------------------
The wizard writes something like this for you except it is very generic
(and way more code). This is more streamlined and easier to manipulate.
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Are you sure that you are using the delete methods, you write that, but in
the same case I have often seen that people then were using the remove
methods, which removes from a datatable, but therefore not from the
database.
Cor
"te_butts" <te*****@discussions.microsoft.comschreef in bericht
news:95**********************************@microsof t.com...
>I have done that and i get different errors all over the place.
Here is what i did to fix the problem.
In the database:
Changed the ProductID to INT, and made Is Identity = yes.
Made ProductID a Primary Key.
Code:
Me.Validate()
Me.ProductsBindingSource.EndEdit()
Me.ProductsTableAdapter.Update(Me.ProductsDataSet. Products)
Deleted Productbindings, tableadapter, and dataset, remade them and all is
good in the world. Select, updating, and inserting works good, but delete
is
not working yet.
"Cor Ligthert[MVP]" wrote:
>Hi,
.Add(New Data.SqlClient.SqlParameter("@ProductID", ProductsID)) etc,
But why do you not simple use
\\\ Me.ProductTableAdapter.Update(Me.ProductsDataset. Products) me.ProductsDataSet.Products.Clear Me.ProductsTableAdapter.Fill(Me.ProductsDataSet.P roducts) ///
Cor
"te_butts" <te*****@discussions.microsoft.comschreef in bericht news:96**********************************@microso ft.com...
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.Pr oducts)
Thanks for the help! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian |
last post by:
I've got a couple questions on the new Datagridview control in VS2005.
1) In the old datagrid control at design time I was able to add multiple
tablestyles with columns from different...
|
by: mark carew |
last post by:
Hi All DataGridView Users.
I have noticed that there seems to be very little useful response to
DataGridView questions in this news group. I have looked at the spanish,
belgium, french, italian...
|
by: TheSteph |
last post by:
Using : Windows 2000 Pro SP4 / VS.NET 2005 / .NET 2.0 / C# - All updates
done.
I have several bugs when I use the DataGridView : When scrolling (or after
scrolling) the grid have these...
|
by: Ryan |
last post by:
My ASP.NET webpage displays an application Form for the user to fill out.
It gets the question information from a SQL database table that contains
multiple questions per application type (so for...
|
by: romerve |
last post by:
Hello; i am having some problems trying to get a form that has a
datagridview to refresh after a new record is created.
I have a MDI container and menu form and add new record form; the menu...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
I'm trying to add a datagridview control to a Windows Form to display
read-only information in visual basic 2005. My understanding is that
datareader will be faster for this purpose. I have the...
|
by: Alcibiade |
last post by:
Hi, I have 2 questions:
1)if width datagridview is shorter than form witdh, user will see
horizontal scrollbar to see all grid.How can I adapt width form to
width datagridview?
2) If a cell...
|
by: dave18 |
last post by:
Hello all!
I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
|
by: Stewart Berman |
last post by:
I have an application that populates a DataGridView control with an XML. file.
1. How do I set up the process so the user initally sees just the headers -- no records.
I have the DataGridView...
|
by: stumorgan |
last post by:
I have a couple questions regarding the DataGridView object...
1) What is the underlying data type that the DataGridView uses if you
are using it unbound and do for instance dgv.Columns.Add(). ...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |