473,803 Members | 4,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inserting into sql db

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.SqlInsertCom mand1.CommandTe xt = "INSERT INTO
StudentInfo(STU DENTID, SURNAME, FIRST_NAMES, PASSWORD,
GENDER, RESIDENCE) VALUES(' " & sNumber.Text & " ' ,' " &
surname.Text & " ' , ' " & fNames.Text & " ' , ' " &
pass.Text & " ' , ' " & gender.Selected Item.Text
& " ' , ' " & res.Text & " ' )"
Me.SqlInsertCom mand1.Connectio n =
Me.SqlConnectio n1
Me.SqlDataAdapt er1.SelectComma nd =
Me.SqlInsertCom mand1
SqlConnection1. Open()

SqlInsertComman d1.ExecuteNonQu ery()
Catch d As Exception
Console.WriteLi ne(d.Message)
End Try
Console.WriteLi ne("Record Added")

Nov 20 '05 #1
2 4587
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
sweetness,

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

some code here.
Usind dataAdapter
SQLCOmmand.conn ection = SQLCOnnection
dim commandBuilder as SQLCommandBuild er
SQLCommand.comm andtext = "Select * from Table"
dataadapter.sel ectCommand = SQLCommand
CommandBuilder = new SQLCommandBuild er(dataAdapter)
dataadapter.fil l(dataset,"tabl e")

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

commandBuilder. refreshSchema()
dataAdapter.Upd ate(dataset,"ta ble")
---------------
Using SQLCOmmand
SQLCOmmand.conn ection = SQLCOnnection
SQLCommand.comm andtext = "Insert into table value @1, @2"
SQLCOmmand.para meters.add("@1" )
SQLCommand.para meters.add("@2" )
SQLCommand.para meters("@1").va lue = value1
SQLCommand.para meters("@2").va lue = value2
SQLCommand.Exec uteNonQuery;

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.SqlInsertCom mand1.CommandTe xt = "INSERT INTO
StudentInfo(ST UDENTID, SURNAME, FIRST_NAMES, PASSWORD,
GENDER, RESIDENCE) VALUES(' " & sNumber.Text & " ' ,' " &
surname.Text & " ' , ' " & fNames.Text & " ' , ' " &
pass.Text & " ' , ' " & gender.Selected Item.Text
& " ' , ' " & res.Text & " ' )"
Me.SqlInsertCom mand1.Connectio n =
Me.SqlConnecti on1
Me.SqlDataAdapt er1.SelectComma nd =
Me.SqlInsertCo mmand1
SqlConnection1. Open()

SqlInsertComman d1.ExecuteNonQu ery()
Catch d As Exception
Console.WriteLi ne(d.Message)
End Try
Console.WriteLi ne("Record Added")

.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5876
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising the images before inserting them as BLOBs. My problem is that (apart from being new to file stuff) my resize function returns a Resource ID which of course is not the same as the file handler that was passed to it, it's a reference to an image...
3
1541
by: James | last post by:
I am in the process of running my site through WC3 validation. I assume the validator at www.w3c.org cant accept cookies and so PHP is attaching &PHPSESSID=lasklijasj09jsad (or similar) to my URLS. The problem is the leading character is a literal & rather than a &amp; and this is stopping the validator telling me my pages are valid. What do I do here --
14
4076
by: Miranda | last post by:
Hi, I have a ASP/vbscript program that generates random passwords. The problem is I need to insert those passwords into an Access database of 327 clients. I have the random password program generating the 327 passwords, but have had no luck inserting them. =============================================== Here is the code that generates the passwords: =============================================== <% Option Explicit %>
1
2590
by: yuchang | last post by:
Hi, Using the FormView control is very efficient. But I want to do some action,like showing a success message or redirect to another page, after inserting, updating and deleting. How do I get these message?
2
1536
by: Krishna | last post by:
Hi, I have developed a for dataentry by using datagird in C# windows application, I am using combocolumns, textbox columns for the same, two readonly textboxcolumns for those readonly columns i will assign the default value through nulltextproperty. I am getting all these fine it is inserting,updating without any problem. But while inserting new rows it is not inserting values related to that readonly textboxes, can some one help me...
12
4917
by: desktop | last post by:
Why does insert only work when specifying an iterator plus the object to be inserted: std::vector<intt; std::vector<int>::iterator it; it = t.begin(); t.insert(it,33); If I use push_back instead I don't need to supply the iterator. But what
0
1768
by: gp | last post by:
I am and have been using PDO for about a year now...and have finally gotten around to solving the "DB NULL value" issues I ran into early on... I am looking for suggestions and techniques to deal with inserting DB NULL values into my MySQL 5.x DB Tables....I am running PHP 5.2.x on BSD 6.x with Apache 2.2.x.... As mentioned I am writing all my web apps using the PDO extension to connect and operate on the database. I realized early...
6
1899
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
2
3098
by: AlexanderDeLarge | last post by:
Hi! I got a problem that's driving me crazy and I'm desperately in need of help. I'll explain my scenario: I'm doing a database driven site for a band, I got these tables for their discography section: Discography --------------------- DiscID
5
2174
by: rando1000 | last post by:
Okay, here's my situation. I need to loop through a file, inserting records based on a number field (in order) and if the character in a certain field = "##", I need to insert a blank record. So here's my method. I created two tables with the same structure as the table I'm inserting from. One table, Split_Temp, is the one I'll be inserting to. The other table, Split_Insert, contains the "Blank" record, which actually just has the word...
0
9700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9121
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.