473,769 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView Questions/Problems

Using VS2005, and SQL 2005 Express.

Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifi er)(newid()) - So it adds
new UI when new row is inserted.
- Second column called ItemCode(NVarCh ar)

VB Form
DataGridView called ProductsDGV

When i created the ProductsDGV it created the BindingDataSour ce,
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.Connection String = "Data Source=ADDLMNAR WP13\SQLEXPRESS ;Initial
Catalog=myDatab ase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn

With cmd.Parameters
.Add(New Data.SqlClient. SqlParameter("P roductID", ProductsID))
.Add(New Data.SqlClient. SqlParameter("I temCode",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("D escription",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("C ost", SqlDbType.NVarC har))
End With

cmd.CommandText = "INSERT INTO
dbo.Products(Pr oductsID,ItemCo de,Description, Cost) VALUES
(@ProductsID,@I temCode,@Descri ption,@Cost)"

cmd.ExecuteNonQ uery()
cnxn.Close()

Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)

Thanks for the help!


Jun 27 '08 #1
4 1676
Hi,

.Add(New Data.SqlClient. SqlParameter("@ ProductID", ProductsID))
etc,

But why do you not simple use

\\\
Me.ProductTable Adapter.Update( Me.ProductsData set.Products)
me.ProductsData Set.Products.Cl ear
Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)
///

Cor
"te_butts" <te*****@discus sions.microsoft .comschreef in bericht
news:96******** *************** ***********@mic rosoft.com...
Using VS2005, and SQL 2005 Express.

Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifi er)(newid()) - So it adds
new UI when new row is inserted.
- Second column called ItemCode(NVarCh ar)

VB Form
DataGridView called ProductsDGV

When i created the ProductsDGV it created the BindingDataSour ce,
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.Connection String = "Data
Source=ADDLMNAR WP13\SQLEXPRESS ;Initial
Catalog=myDatab ase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn

With cmd.Parameters
.Add(New Data.SqlClient. SqlParameter("P roductID", ProductsID))
.Add(New Data.SqlClient. SqlParameter("I temCode",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("D escription",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("C ost",
SqlDbType.NVarC har))
End With

cmd.CommandText = "INSERT INTO
dbo.Products(Pr oductsID,ItemCo de,Description, Cost) VALUES
(@ProductsID,@I temCode,@Descri ption,@Cost)"

cmd.ExecuteNonQ uery()
cnxn.Close()

Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)

Thanks for the help!

Jun 27 '08 #2
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.ProductsBind ingSource.EndEd it()
Me.ProductsTabl eAdapter.Update (Me.ProductsDat aSet.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.ProductTable Adapter.Update( Me.ProductsData set.Products)
me.ProductsData Set.Products.Cl ear
Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)
///

Cor
"te_butts" <te*****@discus sions.microsoft .comschreef in bericht
news:96******** *************** ***********@mic rosoft.com...
Using VS2005, and SQL 2005 Express.

Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifi er)(newid()) - So it adds
new UI when new row is inserted.
- Second column called ItemCode(NVarCh ar)

VB Form
DataGridView called ProductsDGV

When i created the ProductsDGV it created the BindingDataSour ce,
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.Connection String = "Data
Source=ADDLMNAR WP13\SQLEXPRESS ;Initial
Catalog=myDatab ase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn

With cmd.Parameters
.Add(New Data.SqlClient. SqlParameter("P roductID", ProductsID))
.Add(New Data.SqlClient. SqlParameter("I temCode",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("D escription",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("C ost",
SqlDbType.NVarC har))
End With

cmd.CommandText = "INSERT INTO
dbo.Products(Pr oductsID,ItemCo de,Description, Cost) VALUES
(@ProductsID,@I temCode,@Descri ption,@Cost)"

cmd.ExecuteNonQ uery()
cnxn.Close()

Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)

Thanks for the help!


Jun 27 '08 #3
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.Sql Client
Dim da As SqlDataAdapter, ds As Dataset, conn as SqlConnection

Private Sub Form1_Load(...)
conn = new sqlConnection
conn.Connection String = "..."
ds = New Dataset
da = new SqlDataAdapter
da.SelectComman d = New SqlCommand
da.SelectComman d.Connection = conn
da.InserCommand = New SqlCommand
da.InsertComman d.Connection = conn
da.UpdateComman d = New SqlCommand
da.UpdateComman d.Connection = conn

da.SelectComman d.CommandText = "Select * from your table"
da.Fill(ds,"tbl 1")
datagridview1.D ataSource = ds.Tables("tbl1 ")

da.UpdateComman d.CommandText = "Update Table1 Set fld1 = @p1, fld2 = @p2
fld3 = @p3,... Where ID = @ID"
da.UpdateComman d.Parameters.Ad d("@p1", SqlDBType.Varch ar, 50, "fld1")
da.UpdateComman d.Parameters.Ad d("@p2", SqlDBType.Varch ar, 50, "fld2")
...

End Sub

Private Sub datagridview1_C ellValueChanged (ByVal sender As Object, ByVal
e As System.Windows. Forms.DataGridV iewCellEventArg s) Handles
datagridview1.C ellValueChanged
Try
Dim strID As String =
datagridview1.R ows(e.RowIndex) .Cells("ID").Va lue.ToString
Dim s1 As String = datagridview1.C olumns(e.Column Index).Name
Dim drF() As DataRow = ds.Tables("tbl1 ").Select(" ID = " & strID)

Dim strArg As String =
datagridview1.R ows(e.RowIndex) .Cells(e.Column Index).Value.To String.ToUpp
er
datagridview1.R ows(e.RowIndex) .Cells(e.Column Index).Value = strArg

For Each dr As DataRow In drF
dr.BeginEdit()
dr(e.ColumnInde x) =
dgrvInactiveDet ail.Rows(e.RowI ndex).Cells(e.C olumnIndex).Val ue
dr.EndEdit()
Next
Application.DoE vents()
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 ***
Jun 27 '08 #4
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*****@discus sions.microsoft .comschreef in bericht
news:95******** *************** ***********@mic rosoft.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.ProductsBind ingSource.EndEd it()
Me.ProductsTabl eAdapter.Update (Me.ProductsDat aSet.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.ProductTabl eAdapter.Update (Me.ProductsDat aset.Products)
me.ProductsDat aSet.Products.C lear
Me.ProductsTab leAdapter.Fill( Me.ProductsData Set.Products)
///

Cor
"te_butts" <te*****@discus sions.microsoft .comschreef in bericht
news:96******* *************** ************@mi crosoft.com...
Using VS2005, and SQL 2005 Express.

Here is the situation:
SQL
- 1 Table called Products
- First Column called ProductsID (Uniqueidentifi er)(newid()) - So it
adds
new UI when new row is inserted.
- Second column called ItemCode(NVarCh ar)

VB Form
DataGridView called ProductsDGV

When i created the ProductsDGV it created the BindingDataSour ce,
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.Connection String = "Data
Source=ADDLMNAR WP13\SQLEXPRESS ;Initial
Catalog=myDatab ase;Integrated Security=True"
cnxn.Open()
cmd.Connection = cnxn

With cmd.Parameters
.Add(New Data.SqlClient. SqlParameter("P roductID",
ProductsID))
.Add(New Data.SqlClient. SqlParameter("I temCode",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("D escription",
SqlDbType.NVarC har))
.Add(New Data.SqlClient. SqlParameter("C ost",
SqlDbType.NVarC har))
End With

cmd.CommandText = "INSERT INTO
dbo.Products(Pr oductsID,ItemCo de,Description, Cost) VALUES
(@ProductsID,@I temCode,@Descri ption,@Cost)"

cmd.ExecuteNonQ uery()
cnxn.Close()

Me.ProductsTabl eAdapter.Fill(M e.ProductsDataS et.Products)

Thanks for the help!

Jun 27 '08 #5

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

Similar topics

1
3209
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 datasources. Then at run time when I would bind a dataset to the grid it would display the tablestyle associated with the dataset. How do I do this in VS2005? 2) I do all my databinding to the datagridview at run time, but setup my columns as unbound...
2
529
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 equivalent CS newsgroups and the situation would appear to be much the same. Why this is the case, who knows? But, I have found one link that may be of help in understanding the innards of DataGridView.
2
2222
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 problems :
1
1822
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 example on app type may have 3 questions while another has 10). I'm having no problems getting the questions to show up, but I want to also display a text box that allows the user to answer the question, then I will 'INSERT' their answers (which...
1
5051
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 form display the data using a data grid view and the add record form creates an object and passes that data to a class method which creates the record using sqlcommand. The add new record form is loaded after the user clicks on the add button on...
3
8539
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 following questions: 1. Can DataReader be bound DIRECTLY to DataGridView? 2. If DataReader cannot be bound directly to DataGridView, how can I load a DataReader into a DataTable and bind the DataTable to DataGridView? Can the DataTable be a...
0
1216
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 contains a long string, even if I increase height cell, string is only at top....how can I enable "multiline" in a datagridview cell?? Thanks ;)
11
76262
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 else who got stumped like I did. It seems so simple... binding a DataGridView to a List<T>. These are the two general problems that I kept running into: (1) When the data in the list updated, the data on the screen did not update. (2) When I...
2
2930
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 properties set to allow the user to edit data but not add or delete (which will be down in the program). However when I execute the ReadXML method one emtpy row is shown. The starter XML contains: <?xml version="1.0" encoding="utf-8"?>...
1
2362
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(). Is there any way to access that data type directly, since the DataSource field is null when the DataGridView is unbound? 2) Is there any way to add a row which does not have as many columns as the rest of the grid? Basically I have about 10...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.