Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz make changes there. I encountered a problem when user are trying save changes. The following code is executed when the save button is click: -
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
-
-
Dim SQLCon As New SqlClient.SqlConnection("Data Source=BICU111AA\SQLEXPRESS;Initial Catalog=ProteinDatabase;Integrated Security=True")
-
SQLCon.Open()
-
Dim SQLCom As New SqlClient.SqlCommand("SELECT * FROM Table_1", SQLCon)
-
Dim DataAdapter As New SqlClient.SqlDataAdapter(SQLCom)
-
Dim CommandBuilder As New SqlClient.SqlCommandBuilder(DataAdapter)
-
Dim changes As Integer
-
changes = DataAdapter.Update(dt)
-
DataAdapter.Dispose()
-
If changes > 0 Then
-
MsgBox(changes & " changed rows were made.")
-
Else
-
MsgBox("No changes made")
-
End If
-
End Sub
It reports an error when it reaches "changes = DataAdapter.Upd ate(dt)". Can someone advise me how to debug it?
11 4125
Can you please post the exact error message for reference of our experts.
DataAdapter.upd ate() this method expect the Data set as Agumant not DataTable. Plz do tht it may solve your Problem
Frinavale 9,735
Recognized Expert Moderator Expert
Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz make changes there. I encountered a problem when user are trying save changes. The following code is executed when the save button is click: -
Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
-
-
Dim SQLCon As New SqlClient.SqlConnection("Data Source=BICU111AA\SQLEXPRESS;Initial Catalog=ProteinDatabase;Integrated Security=True")
-
SQLCon.Open()
-
Dim SQLCom As New SqlClient.SqlCommand("SELECT * FROM Table_1", SQLCon)
-
Dim DataAdapter As New SqlClient.SqlDataAdapter(SQLCom)
-
Dim CommandBuilder As New SqlClient.SqlCommandBuilder(DataAdapter)
-
Dim changes As Integer
-
changes = DataAdapter.Update(dt)
-
DataAdapter.Dispose()
-
If changes > 0 Then
-
MsgBox(changes & " changed rows were made.")
-
Else
-
MsgBox("No changes made")
-
End If
-
End Sub
It reports an error when it reaches "changes = DataAdapter.Upd ate(dt)". Can someone advise me how to debug it?
First of all...what is your variable dt?
I don't see it declared anywhere in this code.
Secondly, are you actually grabbing any data from your DataGrid while updating?
Thirdly, could you please post the exact error that you are getting so that we can help you solve this problem.
Thanks,
-Frinny
The error message is Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information and it points to the line "changes=DataAd apter.Update(dt )"
anyway, the variable, dt is a datatable that i declared in the beginning of the program.
The error message is Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information and it points to the line "changes=DataAd apter.Update(dt )"
The variable, dt is a datatable that i declared in the beginning of the program.
Lastly, i need to the program to return the number of rows that has changed after the database is saved...
Hope u can help me out thx
Hello, you may do two things to solve:
1)Create the update method yourself, look "Update method data adapter" on google and you'll have plenty.
2)Retrieve the key of the table if any, if you don't have a key you have to create the update method.
C U
Davide
hello, i have the code to the following: -
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
Dim changes As Integer
-
Dim SQLCon As New SqlClient.SqlConnection("Data Source=TP-TM3282WXMI\SQLEXPRESS;Initial Catalog=ProteinDatabase;Integrated Security=True;Pooling=False")
-
SQLCon.Open()
-
Dim DataAdapter As New SqlClient.SqlDataAdapter()
-
DataAdapter.SelectCommand = New SqlClient.SqlCommand("SELECT * FROM Table_1", SQLCon)
-
Dim CommandBuilder As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder(DataAdapter)
-
DataAdapter.Fill(dt)
-
'CommandBuilder.GetUpdateCommand()
-
changes = DataAdapter.Update(dt)
-
-
DataAdapter.Dispose()
-
If changes > 0 Then
-
MsgBox(changes & " changed rows were made.")
-
Else
-
MsgBox("No changes made")
-
End If
-
End Sub
-
But it still displays the same error message
Frinavale 9,735
Recognized Expert Moderator Expert
Sorry, but there's no mention here....are you developing a desktop application or a web application?
If you are using a web application and create the DataTable at the beginning of the program, then this table could possibly be lost during PostBack during the next page request. This could explain the error, as you would be trying to update an empty table.
I m developing a desktop application
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Angie |
last post by:
datagrid ex.
a 1 checkbox
b 2 checkbox
c 3 checkbox
once a user selects these 3 rows from a datagrid and i
want to save the 1, 2, 3 value into the database how do i
do this?
I know how to determine the checkboxes and save data into
|
by: HomeyDaClown |
last post by:
I'm new to the VB.net world and have been reading alot of books and threw newsgroups
Is it even posable to save user input from a form to a data grid. I could just edit the data gri
but would prefer useing the user form to import the data
Any help would be greatly appreciated
Thanks
Homey
|
by: Islamegy |
last post by:
When i press btn_save all changed rows in my grid get saved except the last
editing row...
I want my btn_Save to end editing in the datagrid.. so if user didn't press
"enter" after editing last cell of the current row, I could force this row
to be saved in the datasource.
help plz
|
by: Alpha |
last post by:
Hi, I have a window based program. One of the form has several textboxes and
a datagrid. The textboxes are bind to the same dataset table as the datagrid
and the text changes to reflect different row selected in the datagrid.
I want to save the changes that user make in the textboxes when they select
a different row in the datagrid. I...
|
by: tafs7 |
last post by:
Hello,
I have a custom datagrid control that works great. But I was thinking
about adding some functionality to it. Currently, I use the datagrid
to display one record at a time, and with item templates, if you click
the edit button, the datagrid becomes a nice form to make changes.
Kinda like a big rolodex, and as you page you flip thru...
| |
by: Patty05 |
last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly appreaciated. Thanks.
Code below:
Imports System.Data.OleDb
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form...
|
by: nch1978 |
last post by:
I am new to programming and am sorry if this post is in the wrong area. I have a listbox bound to a table and a datagrid bound to another one with a connection through xml. I can change the data within the grid, with the following through a button on a different tab page within the form, but it does not save changes to the database, just shows...
|
by: toddw607 |
last post by:
Hi all!
I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the user can just click on and edit the cell. I have a save button and when I click the save button the page reloads and the new data is in the cell, however when I close out and come back in the data is no...
|
by: jagjitsurfer |
last post by:
hi,
I am using datagrid view in my solution which displays data from a table of database.
I allows users to directly update, insert or delete data from data grid view, but i can't save the data of the current row of datagridview which user is currently editing.
If user changes the selection from editing row to another row, the data can be...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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. ...
| |
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |