Click here to Skip to main content
15,911,891 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Save As A Chosen Date. [modified*3] Pin
frankiebaby223-Jul-07 15:31
frankiebaby223-Jul-07 15:31 
GeneralRe: Save As A Chosen Date. [modified*3] Pin
RichardBerry23-Jul-07 22:00
RichardBerry23-Jul-07 22:00 
GeneralRe: Save As A Chosen Date. [modified*3] Pin
frankiebaby223-Jul-07 22:22
frankiebaby223-Jul-07 22:22 
QuestionHTML Editor in Vb.net Pin
phyrrix22-Jul-07 6:46
phyrrix22-Jul-07 6:46 
AnswerRe: HTML Editor in Vb.net Pin
ne0h22-Jul-07 7:02
ne0h22-Jul-07 7:02 
AnswerRe: HTML Editor in Vb.net Pin
Naji El Kotob22-Jul-07 8:08
Naji El Kotob22-Jul-07 8:08 
Questionupdateing db Pin
stupid122-Jul-07 3:26
stupid122-Jul-07 3:26 
AnswerRe: updateing db Pin
stupid122-Jul-07 3:27
stupid122-Jul-07 3:27 
Here is the update logic that I have written:
Protected Sub update_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles update.Click
Dim connStr As String = ConfigurationManager.ConnectionStrings("NWConnectionString").ToString()
' Create DB Connection
Dim conn As New SqlConnection(connStr)
'Create Select Statement
Dim strSql As String = "Select * From Employees"
'Create Sql Update Statement
Dim upSql As String = "UPDATE Employees SET LastName=@LastName, FirstName=@FirstName, Title=@Title, Address=@Address," & _
"City=@City, Region=@Region, PostalCode=@PostalCode, HireDate=@HireDate Where EmployeeID=@EmployeeID"
Try
'Create DataAdapter
Dim da As New SqlDataAdapter
da.SelectCommand = New SqlCommand(strSql, conn)

'Create and Fill DataAdapter
Dim ds As New DataSet
da.Fill(ds, "Employees")

'Get the DataTable
Dim dt As DataTable = ds.Tables("Employees")

'Modify the Rows
dt.Rows(0)("LastName") = "@LastName"
dt.Rows(0)("FirstName") = "@FirstName"
dt.Rows(0)("Title") = "@Title"
dt.Rows(0)("Address") = "@Address"
dt.Rows(0)("City") = "@City"
dt.Rows(0)("Region") = "@Region"
dt.Rows(0)("PostalCode") = "@PostalCode"
dt.Rows(0)("HireDate") = "@HireDate"

'Update Employees Table
'Create Command
Dim upCmd As New SqlCommand(upSql, conn)

'Map Parameters
upCmd.Parameters.Add("@LastName", SqlDbType.VarChar, 20, "LastName")
upCmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 10, "FirstName")
upCmd.Parameters.Add("@Title", SqlDbType.VarChar, 30, "Title")
upCmd.Parameters.Add("@Address", SqlDbType.VarChar, 60, "Address")
upCmd.Parameters.Add("@City", SqlDbType.VarChar, 15, "City")
upCmd.Parameters.Add("@Region", SqlDbType.VarChar, 15, "Region")
upCmd.Parameters.Add("@PostalCode", SqlDbType.VarChar, 10, "PostalCode")
upCmd.Parameters.Add("@HireDate", SqlDbType.DateTime, 8, "HireDate")

'Map EmployeeID Parameter
Dim idParam As SqlParameter = upCmd.Parameters.Add("@EmployeeID", SqlDbType.Int, 4, "EmployeeID")
idParam.SourceVersion = DataRowVersion.Original

'Open the connection
conn.Open()

'Update Employees Table
da.UpdateCommand = upCmd
ds.AcceptChanges()
da.Update(ds, "Employees")


Catch ex As Exception
'Display Error
Console.WriteLine("Error: " & ex.ToString())

Finally
'Close Connection
conn.Close()
'Redirect to Home
Response.Redirect("~/Default.aspx")
End Try
End Sub
I know it has something to do with passing the data back to the ds, but I am not sure what I am missing. Also, am I referencing an unknown row properly in the 'Modify Rows' section?

Any and all help is appreciated. I think I am close, but not sure what I am missing.

Stupid1 Confused | :confused:
QuestionHow to replace text until end of the line? Pin
sweehin1822-Jul-07 2:18
sweehin1822-Jul-07 2:18 
AnswerRe: How to replace text until end of the line? Pin
Luc Pattyn22-Jul-07 2:44
sitebuilderLuc Pattyn22-Jul-07 2:44 
GeneralRe: How to replace text until end of the line? Pin
sweehin1822-Jul-07 2:59
sweehin1822-Jul-07 2:59 
GeneralRe: How to replace text until end of the line? Pin
Luc Pattyn22-Jul-07 3:32
sitebuilderLuc Pattyn22-Jul-07 3:32 
GeneralRe: How to replace text until end of the line? Pin
sweehin1823-Jul-07 4:59
sweehin1823-Jul-07 4:59 
GeneralRe: How to replace text until end of the line? Pin
Luc Pattyn23-Jul-07 5:22
sitebuilderLuc Pattyn23-Jul-07 5:22 
GeneralRe: How to replace text until end of the line? Pin
Luc Pattyn23-Jul-07 5:23
sitebuilderLuc Pattyn23-Jul-07 5:23 
GeneralRe: How to replace text until end of the line? Pin
sweehin1823-Jul-07 9:16
sweehin1823-Jul-07 9:16 
GeneralRe: How to replace text until end of the line? Pin
Luc Pattyn23-Jul-07 9:36
sitebuilderLuc Pattyn23-Jul-07 9:36 
GeneralRe: How to replace text until end of the line? Pin
Luc Pattyn22-Jul-07 3:41
sitebuilderLuc Pattyn22-Jul-07 3:41 
GeneralRe: How to replace text until end of the line? Pin
sweehin1822-Jul-07 6:42
sweehin1822-Jul-07 6:42 
QuestionI have problem Pin
wayen22-Jul-07 1:53
wayen22-Jul-07 1:53 
AnswerRe: I have problem Pin
Sathesh Sakthivel22-Jul-07 4:07
Sathesh Sakthivel22-Jul-07 4:07 
GeneralRe: I have problem Pin
Paul Conrad22-Jul-07 5:38
professionalPaul Conrad22-Jul-07 5:38 
AnswerSearch and thou shall find Pin
Luc Pattyn22-Jul-07 9:51
sitebuilderLuc Pattyn22-Jul-07 9:51 
GeneralRe: Search and thou shall find Pin
Paul Conrad22-Jul-07 10:27
professionalPaul Conrad22-Jul-07 10:27 
JokeRe: Search and thou shall find Pin
Luc Pattyn22-Jul-07 10:46
sitebuilderLuc Pattyn22-Jul-07 10:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.