[英]Visual Studio - Unable to view table data
我正在编写一个报告管理器程序。 我从项目 -> 新项目 -> 基于服务的数据库创建了一个数据库。 当我尝试插入时,我没有收到错误。 当我尝试使用 Server Explorer -> Reports -> Show Table Data 查看数据库中的数据时,我得到一个空表。 刷新后,我收到此错误
无法导入数据库。 它要么是不受支持的 SQL 服务器版本,要么是不受支持的数据库兼容性。
我的代码
private void btnSubmit_Click(object sender, EventArgs e)
{
string span = cbSpan.Text;
string reportData = tbReportInput.Text;
DateTime timeStamp = DateTime.Now;
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\\App_Data\\ReportsDB.mdf;Integrated Security=True");
if (tbReportInput.Text == string.Empty)
{
MessageBox.Show("Report must have text!!!!");
}
else
{
try
{
string sqlQuery = "INSERT INTO dbo.Reports(TimeSpan, ReportData, TimeStamp) " +
"VALUES (@TimeSpan, @ReportData, @Date)";
SqlCommand cmd = new SqlCommand(sqlQuery, con);
cmd.Parameters.AddWithValue("@TimeSpan", span);
cmd.Parameters.AddWithValue("@ReportData", reportData);
cmd.Parameters.AddWithValue("@Date", timeStamp);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i != 0)
{
MessageBox.Show(i + " Data Saved");
}
}
catch (SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
我来自 app.config 的连接字符串
<connectionStrings>
<add name="ReportManager.Properties.Settings.ReportsDBConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\App_Data\ReportsDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
尝试从 sql 服务器管理工作室连接到数据库,这似乎是 Visual Studio 中的版本冲突。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.