如何在C#Win应用程序中访问Sql Server数据库表单其他Mashing(Pc) [英] How Can I Access Sql Server Data Base Form Other Mashing (Pc) In C# Win Application

查看:72
本文介绍了如何在C#Win应用程序中访问Sql Server数据库表单其他Mashing(Pc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是win for win应用程序,



i在Windows应用程序中无权访问集中数据库



请帮帮我。



这里我很困惑通过连接的本地服务器访问一个系统数据库使用到其他系统



请一步一步地给连接字符串或任何其他要求做任何想法。

i m new for win application,

i have no any idea to access centralize database in windows application

please help me .

here i have confuse to access one system data base use to other system by connected local server

please give any idea to connection-string or any other requirement to do this, step by step.

推荐答案

Beginners指导通过C#访问SQL Server [ ^ ]将帮助您


using System.Data.SqlClient;







private void button1_Click(object sender, EventArgs e)
{
    string connectionString = "Data Source=SERVERNAME;Initial Catalog=BASENAME;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD";
    SqlConnection conn = new SqlConnection(connectionString);
    conn.Open();
    string cmdText = "select * from TBL1";
    SqlCommand cmd = new SqlCommand(cmdText, conn);
    SqlDataReader rdr = cmd.ExecuteReader();
    DataTable tbl = new DataTable();
    tbl.Load(rdr);
    dataGridView1.DataSource = tbl;
    conn.Close();
}


这篇关于如何在C#Win应用程序中访问Sql Server数据库表单其他Mashing(Pc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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