| |

VerySource

 Forgot password?
 Register
Search
View: 774|Reply: 7

Because of the graduation project, I ask all the experts to connect to SQL, younger brother, thank you!

[Copy link]

4

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-22 07:20:02
| Show all posts |Read mode
I want to ask, 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 use the VB.NET language in Default.aspx.vb. How should I write it? Thank you!
Reply

Use magic Report

0

Threads

322

Posts

115.00

Credits

Newbie

Rank: 1

Credits
115.00

 China

Post time: 2020-1-31 21:45:01
| Show all posts
sure.
Change it to vb.

SqlConnection conn = null;
SqlDataAdapter dapt = null;
DataSet ds = new DataSet ();
string strConnectionString = "Data Source = .; initial catalog = database; uid = sa; pwd = xxx";
string strSQL = "SELECT field from table"
try
{
conn = new SqlConnection (strConnectionString);
conn.Open ();
dapt = new SqlDataAdapter (strSQL, conn);
dapt.Fill (ds, "table1");
DataTable dt = ds.Tabls [0];
if (dt.Rows.Count> 0)
{
this.Text1.Text = dt.Rows [0] ["field"]. ToString ();
}
Ranch
}
catch (System.Exception e)
{
this.Text1.Text = "Error" + e.Message;
}
finally
{
if (conn! = null)
conn.Dispose ();
if (dapt! = null)
dapt.Dispose ();
}
Reply

Use magic Report

3

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-31 22:09:01
| Show all posts
Create connection first
Reply

Use magic Report

0

Threads

58

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-31 22:27:01
| Show all posts
Import System.Data
Import System.Data.Sqlclient
Reply

Use magic Report

1

Threads

18

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-31 23:18:01
| Show all posts
private static void OpenSqlConnection ()
{
    string connectionString = GetConnectionString ();
    using (SqlConnection connection = new SqlConnection (connectionString))
    {
        connection.Open ();
        Console.WriteLine ("ServerVersion: {0}", connection.ServerVersion);
        Console.WriteLine ("State: {0}", connection.State);
    }
}

static private string GetConnectionString ()
{
    return "Data Source = (local); Initial Catalog = AdventureWorks;"
        + "Integrated Security = SSPI;";
}
Reply

Use magic Report

4

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-1 19:45:01
| Show all posts
May I ask, can it be simpler? I'm new, I don't understand
The first floor is ok, but it is written in many places. Can you give the number you want to define?
Reply

Use magic Report

1

Threads

10

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-2-1 22:00:02
| Show all posts
Import System.Data
Import System.Data.Sqlclient
Reference these two at the beginning
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-7 10:45:01
| Show all posts
Dim student_id As String = Request.Cookies ("userInf"). Values ​​("userID")


        Dim mySqlConnection As String
        mySqlConnection = "Data Source = localhost; initial catalog = user; user id = lgw; password = lgw; connect timeout = 30"
        Dim connuser As New Data.SqlClient.SqlConnection (mySqlConnection)
        conn.Open ()

        Dim strSql As String = "select * from users where id ="&student_id
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