WPF项目连接到sqlserver [英] WPF project connection to sqlserver

查看:499
本文介绍了WPF项目连接到sqlserver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

成员我有一个问题,如何用这个proect'的数据连接到数据库的sql server表。

你能建议。


大家你可以看到现在在这个ContactManager.state里面的bin\debug \ContactManager.state是我运行项目时存储数据的文件。


在ContactRepository.cs中有一个_stateFile,其中的值正在被stotred.This变量稍后用于所有操作。

我的问题是如何连接到sql server而不是这个ContactManager.state文件


现在在contactrepository.cs文件中


< code>

展开 | 选择 | Wrap | 行号

解决方案

提示:当您在撰写问题时,有一个按钮在工具栏上包装复制/粘贴代码周围的[code]标签。它有助于一堆。它的按钮上有一个''#''。 有关标签的更多信息。他们很酷。 Check''em出来。


标签是[code] not< code>



我的问题是如何连接到sql server而不是这个ContactManager.state文件

现在在contactrepository.cs文件中



直到有经验的人可以提供更有针对性的建议我可以指向你:


数据库操作方法第1和第2部分
数据库教程第1部分
数据库教程第2部分


我知道与Windows窗体的sql数据连接。

如下所示

< code>

private void button1_Click(object sender,EventArgs e)

{

SqlConnection con = new SqlConnection(" Data Source = STUDENT-1D40FC5 \\ SQLEXPRESS; Initial Catalog = LibraryMgnt; Integrated Security = SSPI");

string query =" insert into BookDetails(Title,Author,Publisher,Subject,No_Of_C opies)values(''" + title.Text +"'',''" + author.Text +"'',''" + textBox3.Text +"'',''" + subject.Text +"'','' " + no.Text +"'')" ;;

SqlCommand cmd = new SqlCommand(query,con);

con.Open();

SqlDataReader reader = cmd.ExecuteReader();

MessageBox.Show(书籍详细信息已保存。);

while(读者) .Read())

{

}

reader.Close();


}

< / code>


我想知道如何在代码中插入_stateFile。

好​​像你看到完整的项目并下载它然后你会看到它使用二进制文件进行数据库连接并插入,更新,删除。


所以到位

< code>

_stateFile = Path.Combine(

AppDomain.CurrentDomain.BaseDirectory,

" ContactManager.state"

< / code>

如何连接到sql数据库或.mdf文件而不是二进制文件。


Members I have a question how to connect to sql server tables of a database with this proect''s data.
Can you suggest .

Members you can see that inside the bin\debug\ContactManager.state now in this ContactManager.state is the file where the data is getting stored when I am running the proj.

There is a _stateFile in the ContactRepository.cs where the values are getting stotred.This variable is later on used for all the operations.
My question is how to connect to sql server instead to this ContactManager.state file

now inside contactrepository.cs file

<code>

Expand|Select|Wrap|Line Numbers

解决方案

TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a ''#'' on it. More on tags. They''re cool. Check''em out.

The tag is [code] not <code>


My question is how to connect to sql server instead to this ContactManager.state file
now inside contactrepository.cs file

Until someone with more experience can offer more targeted advice I can point you toward these:

Database How-to parts 1 and 2
Database tutorial Part 1
Database tutorial Part 2


I know the sql data connection to the windows forms.
Like the following
<code>
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=STUDENT-1D40FC5\\SQLEXPRESS; Initial Catalog=LibraryMgnt;Integrated Security=SSPI");
string query = "insert into BookDetails(Title,Author,Publisher,Subject,No_Of_C opies)values(''" + title.Text + "'',''" + author.Text + "'',''" + textBox3.Text + "'',''" + subject.Text + "'',''" + no.Text + "'')";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
MessageBox.Show("The Book Details are saved.");
while (reader.Read())
{
}
reader.Close();

}
</code>

I want to know how to insert to the _stateFile in the code.
As if you see the full project and download it then you will see that it is using a binary file for the purpose of database connection and insert,update,delete.

So in place
<code>
_stateFile = Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"ContactManager.state"
</code>
how to connect to the sql database or .mdf file rather than a binary file.


这篇关于WPF项目连接到sqlserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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