Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
hi Everyone,
My program is doing good when I suddenly bumped into this problem.
I dont know how to do the next functionality that I need to accomplish.
I am done with inserting values, showing the gridview etc and it works great. Now my problem is the update command.

I have 2 tables
table:
tblDest
Fields:
destLastName
destFname
destEmail

Table: tblSource
Fields:
Sourcelastname
SourceFname
SourceEmai

Now, when I run my update command in sql server, it works great! I just right click the database, click new query and i run this command:
update tblDest set DestEmail =(Select SourceEmail from tblSource where tblSource.SourceFname = tblDest.DestFname and tblSource.SourceLastname = tblDest.DestLastname)

what the query does, is it updates the table tbldest email where lastname and firstname exists in both tables that are equal,
the question is, I want to automate this, I am done with inserting values, the problem is, I dont know how to run the update command,
I tried doing this:
Dim sqlds As New SqlDataSource
        sqlds.ConnectionString = ConfigurationManager.ConnectionStrings("sqlconnect").ConnectionString
        sqlds.ProviderName = ConfigurationManager.ConnectionStrings("sqlconnect").ProviderName
        sqlds.UpdateCommand = "update tblDest set DestEmail =(Select SourceEmail from tblSource where tblSource.SourceFname = tblDest.DestFname and tblSource.SourceLastname = tblDest.DestLastname)"
        DestGrid.DataSource = sqlds
        DestGrid.DataBind()
but nothing happened.

I want to thank you guys in advance for any help.
Posted

The (possibly) simplest way to do an update is to use ExecuteNonQuery[^].
 
Share this answer
 
Comments
serigraphie 21-Mar-11 6:18am    
thank you Mika :D
Wendelius 21-Mar-11 6:31am    
No problem :)
i dont know what your problem is but i think you can try this[^]

Good Luck
 
Share this answer
 
Comments
serigraphie 21-Mar-11 6:18am    
Thanks Ali, but I used the execute nonquery to update like what mike advised and it worked..
Ali Al Omairi(Abu AlHassan) 21-Mar-11 6:23am    
Sir, its 'Mika'
serigraphie 21-Mar-11 7:56am    
oh sorry, typo :) thanks for the correction though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900