Adding a row to a table help!

  • Thread starter Thread starter Bonzol
  • Start date Start date
B

Bonzol

Hey there,
(using a windows applicaiton) What I have is a database with engineers
on it in a table tited 'Engineer', what I want to do is be able to add
a new engineer to the database. Via text boxes and a submit button
instead of a data grid.

I have the data connections n such and have fiddled around a bit and
tried this code.

my dataset is 'update1'


visual basic
code:--------------------------------------------------------------------------------
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click

Dim Name As String

Dim qual As String

Dim mob As String

Dim phone As String

Dim NOK As String

Dim specId As String

Dim newEngineer As DataRow

Name = txtName.Text

qual = txtQual.Text

mob = txtMobile.Text

phone = txtPhone.Text

NOK = txtNOK.Text

specId = txtSpecID.Text

newEngineer = Update1.Engineer.NewRow

newEngineer("Eng-name") = Name

newEngineer("Eng-Qual") = qual

newEngineer("Eng-Mobile") = mob

newEngineer("Eng-Phone") = phone

newEngineer("ENG-NOK") = NOK

newEngineer("Spec-ID") = CInt(specId)

Update1.Engineer.Rows.Add(newEngineer)

OleDbDataAdapter1.Update(Update1)
 
Hello Bonzol,

Whoa.. way, WAY too much stuff goin on there for a simple row insert.
Oh, and I dont care what anyone says, typed datasets are of the Debbil.

Assumes .NET Framework 2.0:


Public Sub ScreenToDatabase()

Dim tConnection As SqlConnection = New SqlConnection(yourConnectionStringHere)
Dim tCommand As SqlCommand = New SqlCommand

With tCommand
..Connection = tConnection
..CommandType = CommandType.Text
..CommandText = "INSERT INTO table (field1, field2, field3, fieldN) VALUES
(@field1, @field2, @field3, @fieldN)
With .Parameters
..AddWithValue("@field1", textbox1.text)
..AddWithValue("@field2", textbox2.text)
..AddWithValue("@field3", textbox3.text)
..AddWithValue("@fieldN", textboxN.text)
End With
End With
tConnection.Open
tCommand.ExecuteNonQuery
tConnection.Close

End Sub
 
woahh, your code kinda feaked me out there, never seen anything like
that before.

Im a total n00b at this, so can I just put that in a button? and it'll
go once I fill in the details?
 
im also uncertain of what to put here?


Dim tConnection As SqlConnection = New
SqlConnection(yourConnectionStringHere)
Dim tCommand As SqlCommand = New SqlCommand


my dataadapter is

OleDbDataAdapter1

and my connection is

OleDbConnection1

anything else I got no idea
 
Back
Top