| |

VerySource

 Forgot password?
 Register
Search
View: 657|Reply: 3

Seeking to use the simplest VB.NET language to connect SQL in ASP.NET

[Copy link]

4

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-25 14:40:01
| Show all posts |Read mode
I don't want to use in Default.aspx
       
<% @ Import Namespace = "System.Data"%>
<% @ Import Namespace = "System.Data.Sqlclient"%>
       
This method is connected to SQL. I want to write in VB.NET language in Default.aspx.vb. Please give me the simplest connection method, because I am a novice, I am afraid that it is too deep

Please masters give detailed code, if there is a place to define, please give a definition.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-14 08:45:01
| Show all posts
First, reference the code Imports System.Data.SqlClient at the top of the Default.aspx.vb page.
Then give you an example to understand.
Dim con As New SqlConnection ("server = .; database = jie; uid = sa")
// server =. It means the machine is connected, the database name is added with the database name you want to connect, the user name and password are your own.
        Dim cmd As New SqlCommand ("select Uid from user table where user name = '"&TextBox1.Text&"' and user password = '"&TextBox2.Text&"'", con)
        Dim dr As SqlDataReader
        con.Open ()
        dr = cmd.ExecuteReader
        If dr.Read Then
            Response.Redirect ("WebForm1.aspx")
        Else
            Response.Write ("<script> alert ('The username or password is wrong') </ script>")

        End If
        dr.Close ()
        con.Close ()
Reply

Use magic Report

1

Threads

18

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-2-14 09:00:01
| Show all posts
dim con as sqlconnection = New SqlConnection (System.Configuration.ConfigurationManager.ConnectionStrings ("sweaterConnectionString"). ToString)
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 United States

Post time: 2020-2-14 12:00:01
| Show all posts
First add this sentence in the config file:
<appSettings>
<add key = "StrCon" value = "server = IP or service product name; uid = sa; pwd =; database = database name" />
</ appSettings>

Then when you want to connect to the database in the .vb file, add this sentence:
dim conn as new SqlConnection
conn = System.Configuration.ConfigurationSettings.AppSettings (StrCon)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list