从SQL SERVER的数据库中检索数据 [英] retriving data from data base of SQL SERVER

查看:149
本文介绍了从SQL SERVER的数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

这是我与数据库的连接代码.我在SQL Server 2008中创建的数据库.
这给了我一个例外,那就是无法重新定义的数据库格式.我的数据库格式是.mdf

代码如下

Hi All

here is my code of connectivity with th data base . Data base i created in the SQL Server 2008 .
this give me exception that unrecogonized data base format . the format of my data base is .mdf

code is as follows

System.Data.OleDb.OleDbConnection con;
System.Data.OleDb.OleDbDataAdapter da;
DataSet ds1;

private void Form1_Load(object sender, EventArgs e)
{

      con = new System.Data.OleDb.OleDbConnection();
      ds1 = new DataSet();

      con.ConnectionString=" PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\VisualStudio\\dbCreate\\dbCreate\\Database1.mdf"
      con.Open();
      string sql = "SELECT * From FWorkerTable";
      da = new System.Data.OleDb.OleDbDataAdapter(sql, con);
      da.Fill(ds1, "FWorkerTable");
       con.Close() ;
}




请帮助我
在此先感谢
[edit]已添加代码块,忽略HTML ..."选项已禁用-OriginalGriff [/edit]




Please help me
Thanks in advance
[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]

推荐答案

看看这篇文章

通过C#访问SQL Server的入门指南 [ connectionstrings.com [
Have a look at this article

Beginners guide to accessing SQL Server through C#[^]

Also, have a look at connectionstrings.com[^] for SQL 2008 connection strings

If you''ve created a SQL2008 database, you should use the SqlConnection object (System.Data.SqlClient) and appropriate connection string


检查您的数据库是否为JET格式:可能是而是使用ACE格式.试试:
Check that your database is in JET format: it may be in ACE format instead. Try:
provider=Microsoft.ACE.OLEDB.12.0


这篇关于从SQL SERVER的数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆