.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 19th, 2013, 12:51 PM
garik111 garik111 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 garik111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 38 sec
Reputation Power: 0
Help with connecting to DB and searching row.

Hi
I am new with asp.net.
I have read and tried a lot but with no result.
I have a table MS SQL :

id start end distance
1 madrid paris 300
2 moscow pitsburg 1000
3 NY california 2000

I also have 2 textboxes. so if first txtbox = moscow and second txtbox = pitsburg , I want to print 1000.
please help me.

Reply With Quote
  #2  
Old February 19th, 2013, 03:01 PM
Tr1tium Tr1tium is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 Tr1tium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 34 sec
Reputation Power: 0
Hello,

in VB.NET:


Code:
Dim connectionString As String
Dim sql As String
Dim pwd As String
Dim user As String
Dim sqlserv As String
Dim sqldb As String

sqlserv = localhost\sqlexpress 'your server
sqldb = mydbs 'the database 
user = sa 'user who has access to the db
pwd = admin 'user's password

'The connection string below
connectionString = "Data Source=" & sqlserv & ";Initial Catalog=" & sqldb & ";User ID=" & user & ";Password=" & pwd

Dim sqlSelect As String

'SQL select below dbo.Table is your table which contains the information, also you can order if you want

sqlSelect = "SELECT Id, Start, End, Distance FROM dbo.Table WHERE (Start = '" & TextBox1.Text & "') AND (End = '" & TextBox2.Text & "' ORDER BY Distance "

Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand

sqlCnn = New SqlConnection(connectionString)

Dim dataadapter As New SqlDataAdapter(sqlSelect, connectionString)

Dim distance As string

        Try
            sqlCnn.Open()
            sqlCmd = New SqlCommand(sql, sqlCnn)
            Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
While sqlReader.Read() distance = sqlReader.Item("distance") End While
sqlReader.Close() sqlCmd.Dispose() sqlCnn.Close() MessageBox.Show(distance, "Result") Catch ex As Exception MessageBox.Show("Houston we have a problem...", "Error") End Try

Reply With Quote
  #3  
Old February 19th, 2013, 04:46 PM
garik111 garik111 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 garik111 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 38 sec
Reputation Power: 0
C#?

Quote:
Originally Posted by garik111
Hi
I am new with asp.net.
I have read and tried a lot but with no result.
I have a table MS SQL :

id start end distance
1 madrid paris 300
2 moscow pitsburg 1000
3 NY california 2000

I also have 2 textboxes. so if first txtbox = moscow and second txtbox = pitsburg , I want to print 1000.
please help me.

Maybe C#??

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Help with connecting to DB and searching row.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap