Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to perform insert query to SQL Server

Author  Topic 

associates
Starting Member

31 Posts

Posted - 2006-09-01 : 03:44:41
Hi,

I was wondering how i could perform query say insert a new record if i use Visual Basic .NET as the front end and SQL Server 2000 as the backend.

Thank you in advance.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-01 : 03:47:40
INSERT INTO SomeTable (SomeCols...) VALUES (1, 2, 3...)

or

INSERT INTO SomeTable (SomeCols...) SELECT SomeCols FROM OtherTable


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-01 : 04:10:58
Peso,
I think what he expects is front-end way to insert data (using may be datasets etc.) Here, is one way:

Dim sqltext As String
Dim cmdresults As Integer
sqltext = "Insert into Table(col1,col2) values(1,2)"

OleDbCommand1.CommandType = CommandType.Text
OleDbCommand1.CommandText = sqltext

OleDbConnection1.Open()
cmdresults = OleDbCommand1.ExecuteNonQuery()
OleDbConnection1.Close()


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-01 : 04:31:15
I assumed he had knowledge in vb.net and lacked knowledge in SQL.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-02 : 11:59:35
Learn SQL

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

associates
Starting Member

31 Posts

Posted - 2006-09-06 : 04:17:16
Thank you to you all for your help.

Honestly, i have a better knowledge of SQL than VB studio .NET 2003. I was trying to learn it myself thru the online help but couldn't find the one that help me with for example, to populate a listbox with the records taken from the SQL Server. But if you know anything, i'm more than happy to heed it.

Thanks a lot for your help
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-06 : 04:22:14
quote:
Originally posted by associates

Thank you to you all for your help.

Honestly, i have a better knowledge of SQL than VB studio .NET 2003. I was trying to learn it myself thru the online help but couldn't find the one that help me with for example, to populate a listbox with the records taken from the SQL Server. But if you know anything, i'm more than happy to heed it.

Thanks a lot for your help



Here is an example code for filling dropdown listbox, see whether it is of any help to you:

[url]http://www.aspfree.com/c/a/ASP-Code/Populate-a-Dropdown-List-box-using-VBNET-and-Codebehind-page/[/url]

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

associates
Starting Member

31 Posts

Posted - 2006-09-08 : 00:21:21
Hi Harsh_athalye

Thank you for your help.

I hope this time, i'm not asking a big favor of you. What i've been doing is to try out some of the codes from the "101 VB.Net samples" zip file i downloaded from the internet. I'm trying out the project called "How to data entry sample". I notice that there is a ListItem object created there. My question is if you look at the frmMain.vb, there is a sub for PopulateProductList().

Here is the code quoted
objListItem = New ListItem(drSQL.Item("ProductName").ToString(), _
CInt(drSQL.Item("ProductID"))
lstProducts.Items.Add(objListItem)

It appears to me that there should be two columns on the listbox, one shows the Product Name and the other is the ProductID. But why does it only show one columns that is ProductName in the listbox when running the project?

What happens to the ProductID?

Thank you in advance
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-09-08 : 03:48:49
Because you interpreted it wrongly.

Actually, when you say

objListItem = New ListItem(drSQL.Item("ProductName").ToString(), _
CInt(drSQL.Item("ProductID"))


you are not creating multi-column listbox...First argument is what you are going to display while second argument stands for the underlying value for that item.

For e.g. you may want to show Emp names in list box, but on selection of name you may want to get its associated emp id for the query purpose. So in this case, you would code like

objListItem = New ListItem(drSQL.Item("EmpName").ToString(), _
CInt(drSQL.Item("EmpID"))




Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

associates
Starting Member

31 Posts

Posted - 2006-09-10 : 20:15:22
Harsh_athalye,

Thank you for your reply and your clear explanation.

Yes, you're right that i misinterpreted it because i was desperate to want the listbox to show multicolumns but couldnot find a way to do it. I'm still learning my way around .NET. I learnt VB before but it's been a while i haven't touched it.

So i was wondering if there is a way of displaying multicolumns listbox and also wonder if there are good VB .NET books around that explains well on the development of VB applications.

Thank you in advance



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-10 : 20:35:33
It is better to post .NET related questions at related forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -