有关如何连接到SQL Server的建议 [英] Advice on how to connect to SQL Server

查看:67
本文介绍了有关如何连接到SQL Server的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个连接到SQL Server的应用程序.我该怎么做?

I am looking to create an application which connects to SQL Server. How can I do this?

推荐答案

您学会了不大声喊叫和阅读.在每个初学者的C#书籍中以及整个Internet上,都连接到数据库.
You learn to not SHOUT and read. Connecting to a database is in every beginners C# book and all over the internet.


您好,
我觉得这段代码必须解决您的查询
Hello,
I feel this code must solve your query
using System.Data.SqlClient; //use this namespace

SqlConnection con = new SqlConnection();
//setting the connection string property
con.ConnectionString = "Data Source=.;Initial Catalog=RJIT;Integrated Security=True";
//open the connection
                    con.Open();
//query
string mycommand = "insert into receipt values(@student_id,@amount_paid,@student_name)";

       SqlCommand cmd = new SqlCommand(mycommand, con);
                    
 cmd.Parameters.AddWithValue("@student_id", comboBox1.Text);
 cmd.Parameters.AddWithValue("@amount_paid", txtreceiptstudamount.Text);
  cmd.Parameters.AddWithValue("@student_name", txtreceiptstudname.Text);

                    int x = cmd.ExecuteNonQuery();
                    if (x != 0)
                    {
//show message box when data is inserted 
                       MessageBox.Show("Data added");
                                  

                    }
//close the connection
                    con.Close();


一旦找到有用的答案,就对我的答案进行评分
谢谢&问候
基数:rose:


Do rate my answer once you find it useful
Thanks & Regards
Radix :rose:


SqlConnection您的连接名称= new SqlConnection(数据源=.\\ SQLEXPRESS; AttachDbFilename = | DataDirectory | \\您的Database_name.mdf;集成安全性= True;用户Instance = True);




这是sql server数据库2005的连接字符串.
SqlConnection your connection name = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\your Database_name.mdf;Integrated Security=True;User Instance=True");




this is the connection string for sql server database 2005


这篇关于有关如何连接到SQL Server的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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