| |

VerySource

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

Compiler Error Message: CS0117: "string" does not contain a definition for "myConnection"

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 United States

Post time: 2020-2-15 05:30:02
| Show all posts |Read mode
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class lx2: System.Web.UI.Page
{
    protected void Page_Load (object sender, EventArgs e)
    {
        string connStr = System.Configuration.ConfigurationSettings.AppSettings ["connString"];

        SqlConnection myConnection = new SqlConnection (connStr);

        string queryStr = "select * from DA";

   Line 22 SqlDataAdapter myDataAdapter = new SqlDataAdapter (queryStr.myConnection);
    }

}
I am a newbie and just learned ASP.NET. I have some problems when practicing ADO.NET database connection, please help me?

The error was: Compiler error message: CS0117: "string" does not contain a definition of "myConnection"

Line 22
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-15 02:30:01
| Show all posts
SqlDataAdapter myDataAdapter = new SqlDataAdapter (queryStr.myConnection);
should be

SqlDataAdapter myDataAdapter = new SqlDataAdapter (queryStr, myConnection);
You have written the comma as a dot, the system judges that myConnection is a member of queryStr, so this compilation error occurs
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-4-15 10:15:01
| Show all posts
Positive Solutions Upstairs
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-4-15 10:30:02
| Show all posts
Fainted, Fan made such a small mistake, hehe, but thank you ~~~
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