Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Inserting a New Record.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Inserting a New Record.

 Post Reply Post Reply
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: Inserting a New Record.
    Posted: 02 June 2005 at 2:22pm
    Right now the database uses a DetailView to show one record. The person then has the opportunity to select that one record as being "used". When this occurs the program needs to pull information from the one table (Games) and insert the information into a different table (LastPlayed). Here is my current code:
Dim key As DataKey = DetailsView1.DataKey
Dim varid As String
varid = key.Value.ToString()
Label1.Text = key.Value.ToString()
Dim sql As String
sql = "INSERT INTO [LastPlayed] (uID, gID, LastPlayedDate) VALUES (" & Profile.UserName & ", " & varid & ", " & DateTime.Now & ")"
SqlDataSource1.InsertCommand = sql
    Anyways, I'm just generally over my head in this area, any websites w/documentation on SQL in ASP.NET 2.0 would be appreciated as well as specific tips on how to handle this code.
David.
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2005 at 5:18pm
To simplify my question....
   How can one update a database without using GridView, DetailsView, etc. Shouldn't one be able to do something like this:
SqlDataSource.InsertCommand = "INSERT INTO (tName) values ('james')"
SqlDataSource.ExecuteNonQuery()
David.
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 03 June 2005 at 5:46pm
Just been messing about with the Data Access Model of .NET 2.0, this might help:

Create a new class with similar code (I'm gonna call my class TestClass):

Public Sub InsertData(string name)
Dim conn As New SqlConnection("...")
'Blah blah blah
'Execute the insert statement
End Sub

Then drop a ObjectDatasource into your page, change the TypeName property to TestClass, then change the InsertMethod to InsertData and click on the InsertParameters...

Add a new Profile parameter and set the property...

Then when your ready just go ObjectDatasource1.Insert();
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Posted: 06 June 2005 at 10:21am
Here is my new code that now works:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim key As DataKey = DetailsView1.DataKey
        Dim varid As String
        varid = key.Value.ToString()
        Label1.Text = key.Value.ToString()
        Dim username As String
        username = Profile.UserName
        Dim sql As String
        sql = "INSERT INTO LastPlayed (uID, gID, LastPlayedDate) VALUES ('" & username & "', '" & varid & "', '" & DateTime.Now & "')"
        SqlDataSource1.InsertCommand = sql
        SqlDataSource1.Insert()
End Sub
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.