Hello,
On my page, I have only one SQL data source and one GridView. I would like to use My Data Source is for different tables I have in the database. SELECT statement works fine. However, when I try to update the data in any other table except the first/default table of datasource then my page for some reason shows the rows of first/default table.
In the 2nd scenario if I remove the "SELECTCOMMAND" and "UPDATECOMMAND" from SQLDataSource on the "aspx" page code view, then I click the Edit button for the first time it doesnt show the gridview. But when for the second time, I select another table from the drop down then it shows that table in the edit mode. So when I try to update the row, I get the following error.
“Updating is not supported by data source 'myDataSource' unless UpdateCommand is specified.”
If you see my code, I am updating the UpdateCommand dynamically.
I am just curious if one data source works for one table specifically. What’s the best approach for doing what I described above. -
Protected Sub ddlTable_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlTable.SelectedIndexChanged
-
Dim strSelect, strColumns As String
-
-
strColumns = ""
-
-
Select Case ddlTable.SelectedValue
-
Case "businesslistings"
-
strColumns = "*"
-
myDataSource.UpdateCommand = "UPDATE businesslistings SET Title=@Title, Address=@Address,Phone=@Phone, Description=@Description WHERE ID=@ID"
-
myDataSource.DeleteCommand = "Delete businesslistings WHERE ID=@ID"
-
Case "jobs"
-
strColumns = "*"
-
myDataSource.UpdateCommand = "UPDATE jobs SET Title=@Title, Location=@Location,Compensation=@Compensation, Description=@Description,Phone=@Phone WHERE ID=@ID"
-
myDataSource.DeleteCommand = "Delete jobs WHERE ID=@ID"
-
Case "rentals"
-
strColumns = "*"
-
myDataSource.UpdateCommand = "UPDATE rentals SET Name=@Name, Address=@Address,Phone=@Phone, Email=@Email,Rent=@Rent, Description=@Description ID=@ID"
-
myDataSource.DeleteCommand = "Delete rentals WHERE ID=@ID"
-
Case "sales"
-
strColumns = "*"
-
myDataSource.UpdateCommand = "UPDATE sales SET Name=@Name, Item=@Item,Phone=@Phone, Email=@Email,Price=@Price, Description=@Description WHERE ID=@ID"
-
myDataSource.DeleteCommand = "Delete sales WHERE ID=@ID"
-
End Select
-
-
-
strSelect = "SELECT " & strColumns & " FROM " + ddlTable.SelectedValue
-
myDataSource.SelectCommand = strSelect
-
-
lblMessage.Text = myDataSource.SelectCommand & "<br>" & myDataSource.UpdateCommand & "<br>" & myDataSource.DeleteCommand
-
'Response.Write(strSelect)
-
End Sub
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
If Session("loginSuccessful") = False Then
-
Response.Redirect("login.aspx")
-
End If
-
-
If Not IsPostBack Then
-
myDataSource.SelectCommand = "SELECT Title,Address,Phone,Description FROM businesslistings"
-
myDataSource.UpdateCommand = "UPDATE businesslistings SET Title=@Title, Address=@Address,Phone=@Phone, Description=@Description WHERE ID=@ID"
-
myDataSource.DeleteCommand = "Delete businesslistings WHERE ID=@ID"
-
lblMessage.Text = "Postback " & IsPostBack & "<br>" & myDataSource.SelectCommand & "<br>" & myDataSource.UpdateCommand & "<br>" & myDataSource.DeleteCommand
-
End If
-
-
End Sub
-
0 1245 Sign in to post your reply or Sign up for a free account.
Similar topics
by: mimo |
last post by:
Hello,
I have seen samples on how to pull data from one table and save back to it
using the Form View control.
How do I pull from multiple tables and save back to multiple tables on one...
|
by: ApexData |
last post by:
I have 2 tables: Table1 and Table2.
Neither one has a primary key because each table will only have
1-record.
My form is a SingleForm unbound with tabs (my desire here).
Using this form, in...
|
by: rlish |
last post by:
I have a database with multiple tables that are all linked by a "site
id" field. For any given record the site id field is identical within
all the tables. Is there anyway to create a form with a...
|
by: chopin |
last post by:
I am using Microsoft Access, and VBA. I was wondering if it was possible to select multiple tables using DAO. For example, here is the code I am thinking should work, but doesn't:
sSQL =...
|
by: dilchahatahai |
last post by:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft
Public Class Form1
'Dim rpt As New final() 'The report you created.
Dim rpt As New CrystalReport1()...
|
by: Kimg0123 |
last post by:
I would like to be able to append data from multiple tables into a single summary table using either an event procedure for the On Load or On Open properties on a form, but cannot seem to figure this...
|
by: 5095 |
last post by:
Hi,
i want to import data in multiple tables from a single text file (each field is seprated by pipe sign and each record is seprated by asterisk * ).
Please guide me to the appropriate way.
...
|
by: varunkumarid |
last post by:
hai to one and all...
I am using The VB.Net 2005 and SQL server2000 ..
I need to insert the Data into multiple tables at once...
if you know about this Concept please Reply quick
|
by: obtrs |
last post by:
show data of multiple tables?
i have 3 tables i want to show the data from them to a page.
table1 "trip"
table2 "seat"
table3 "user_information"
show all the data of table one which is...
|
by: NareshN |
last post by:
Hi All,
I have this tables.I want to upload excel file data to multiple tables.
Excel file consist of EmpName,1 week dates with data(TimeIn and TimeOut).
I want to insert EmpName into...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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: 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,...
| |