You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022 Pro中创建StudentDataDataContext实例时遇BC30516错误求助

Fix for BC30516 Error in StudentDataDataContext Initialization

The error BC30516: Overload resolution failed because no accessible 'New' accepts this number of arguments occurs because your StudentDataDataContext class does not have a public parameterless constructor. LINQ to SQL DataContext classes generated by Visual Studio require a connection string to initialize, as they need to connect to your database.

Solutions

1. Pass the connection string directly to the constructor

Replace your initialization code with the full connection string for your database:

Protected Sub showAll()
    Dim db As New StudentDataDataContext("Data Source=YourServerName;Initial Catalog=YourDatabaseName;Integrated Security=True")
    Dim Marks = From Mark In db.Marks _
                Select New With {Mark.ModuleInformation.ModuleCode, Mark.ModuleName, Mark.Marks, Mark.Grade, Mark.ModuleInformation.Credit, Mark.Comments, Mark.ModuleInformation.ModuleInformation}
    GridView1.DataSource = Marks
    GridView1.DataBind()
End Sub

Replace YourServerName and YourDatabaseName with your actual server and database details.

2. Use the connection string from your configuration file

If you have a connection string defined in web.config (for web apps) or app.config (for desktop apps):
First, confirm the connection string entry exists:

<connectionStrings>
    <add name="StudentDataConnectionString" 
         connectionString="Data Source=YourServerName;Initial Catalog=YourDatabaseName;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Then initialize the DataContext using the connection string name:

Protected Sub showAll()
    Dim db As New StudentDataDataContext("StudentDataConnectionString")
    Dim Marks = From Mark In db.Marks _
                Select New With {Mark.ModuleInformation.ModuleCode, Mark.ModuleName, Mark.Marks, Mark.Grade, Mark.ModuleInformation.Credit, Mark.Comments, Mark.ModuleInformation.ModuleInformation}
    GridView1.DataSource = Marks
    GridView1.DataBind()
End Sub

3. Use the generated connection string property (if available)

Many Visual Studio-generated DataContext classes include a static ConnectionString property that pulls the value from configuration. If this exists, use:

Protected Sub showAll()
    Dim db As New StudentDataDataContext(StudentDataDataContext.ConnectionString)
    Dim Marks = From Mark In db.Marks _
                Select New With {Mark.ModuleInformation.ModuleCode, Mark.ModuleName, Mark.Marks, Mark.Grade, Mark.ModuleInformation.Credit, Mark.Comments, Mark.ModuleInformation.ModuleInformation}
    GridView1.DataSource = Marks
    GridView1.DataBind()
End Sub

Verify Constructor Availability

If you're unsure which constructors are available, right-click StudentDataDataContext in Visual Studio and select Go To Definition to view the class's constructor signatures.

内容的提问来源于stack exchange,提问作者Victor Hernando

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 07:42:24