By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

inserting into sql db

P: n/a
I'm new to this and desperately need help, I'm trying to
insert into an sql db and i have no idea what to do and
why.
i created an sqladapter, and an sqlconnection by dragging
and dropping.
this is a piece of my code:
Try
Me.SqlInsertCommand1.CommandText = "INSERT INTO
StudentInfo(STUDENTID, SURNAME, FIRST_NAMES, PASSWORD,
GENDER, RESIDENCE) VALUES(' " & sNumber.Text & " ' ,' " &
surname.Text & " ' , ' " & fNames.Text & " ' , ' " &
pass.Text & " ' , ' " & gender.SelectedItem.Text
& " ' , ' " & res.Text & " ' )"
Me.SqlInsertCommand1.Connection =
Me.SqlConnection1
Me.SqlDataAdapter1.SelectCommand =
Me.SqlInsertCommand1
SqlConnection1.Open()

SqlInsertCommand1.ExecuteNonQuery()
Catch d As Exception
Console.WriteLine(d.Message)
End Try
Console.WriteLine("Record Added")

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

"sweetness" <ch******@yahoo.com> schrieb:
I'm new to this and desperately need help, I'm trying to
insert into an sql db and i have no idea what to do and


Notice that you will have a better chance to get an answer if you post the
question to the ADO.NET newsgroup:

news://msnews.microsoft.com/microsof...amework.adonet

Web interface:

http://msdn.microsoft.com/newsgroups...amework.adonet

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
sweetness,

you have to use dataAdapter with dataset
Or you only use SQLcommand to insert record.

some code here.
Usind dataAdapter
SQLCOmmand.connection = SQLCOnnection
dim commandBuilder as SQLCommandBuilder
SQLCommand.commandtext = "Select * from Table"
dataadapter.selectCommand = SQLCommand
CommandBuilder = new SQLCommandBuilder(dataAdapter)
dataadapter.fill(dataset,"table")

dataRow = dataset.table(0).newRow
dataRow(0) = value1
dataRow(1) = value2
dataset.table(1).rows.add(datarow)

commandBuilder.refreshSchema()
dataAdapter.Update(dataset,"table")
---------------
Using SQLCOmmand
SQLCOmmand.connection = SQLCOnnection
SQLCommand.commandtext = "Insert into table value @1, @2"
SQLCOmmand.parameters.add("@1")
SQLCommand.parameters.add("@2")
SQLCommand.parameters("@1").value = value1
SQLCommand.parameters("@2").value = value2
SQLCommand.ExecuteNonQuery;

Hope it can help you
Kwok
-----Original Message-----
I'm new to this and desperately need help, I'm trying to
insert into an sql db and i have no idea what to do and
why.
i created an sqladapter, and an sqlconnection by dragging
and dropping.
this is a piece of my code:
Try
Me.SqlInsertCommand1.CommandText = "INSERT INTO
StudentInfo(STUDENTID, SURNAME, FIRST_NAMES, PASSWORD,
GENDER, RESIDENCE) VALUES(' " & sNumber.Text & " ' ,' " &
surname.Text & " ' , ' " & fNames.Text & " ' , ' " &
pass.Text & " ' , ' " & gender.SelectedItem.Text
& " ' , ' " & res.Text & " ' )"
Me.SqlInsertCommand1.Connection =
Me.SqlConnection1
Me.SqlDataAdapter1.SelectCommand =
Me.SqlInsertCommand1
SqlConnection1.Open()

SqlInsertCommand1.ExecuteNonQuery()
Catch d As Exception
Console.WriteLine(d.Message)
End Try
Console.WriteLine("Record Added")

.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.