C#在windows身份验证状态下,如何使用代码连接到SQL呢?
解决方案 »
- TCP/UDP 协议问题
- dataGridView多列求和的问题
- 如何判断数据库中的数据,来弹出窗口!
- 求.net2005下载地址?
- 关于ListView?怎样设置才能让Id,Name,Age这三项的内容都能被修改!??
- 从数据库取值
- 谁能给我讲讲try...catch语句是什么意思啊??
- vs.net里如何生成windows应用程序,才能使它在没安装.net 框架的机器上运行?谢~
- 很菜的问题:C# 可以做什么,需要什么环境和条件?能做类似java applet的东西吗?
- 关于多线程操作DataTable锁的问题
- datagridview绑定数据问题
- C# 窗体程序 如何读写网站的数据库 ACCESS
"Integrated Security=SSPI;database=...;server=...;Initial Catalog=..."
string source= "server=服务器名;integrated security=SSPI;database=数据库名";
SqlConnection conn = new SqlConnection(source);
<connectionStrings>
<add name="tempdbConnectionString" connectionString="Data Source=192.168.91.169;Initial Catalog=meeting_Data;User ID=sa;Password=albbsxy123456" providerName="System.Data.SqlClient"/>
</connectionStrings>
代码
string connectionString =ConfigurationManager.ConnectionStrings["tempdbConnectionString"].ConnectionString;
using (SqlConnection con = connectionString )
{
con.Open();
SqlCommand cmd = new SqlCommand(SQL语句, con);
cmd.ExecuteNonQuery();
}
protected void butsubmit_click(object sender, EventArgs e)
{
SqlConnection sqlconnection;
string sqlconnstr = "Data Source=.;Initial Catalog=chapter;Integrated Security=True" ;
sqlconnection=new SqlConnection(sqlconnstr);
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = sqlconnection;
sqlcommand.CommandText = "insert into ueserInfo (username,psw) values('" + this.username.Text + "','" +this. password.Text + "') ";
int result = sqlcommand.ExecuteNonQuery();
//sqlconnection.Close();
if (result == 1)
{
Label2.Text="注册成功!";
labcontent.Text = "您的用户名是 :" + username.Text;
Label1.Text = "您的密码是 :" + password.Text;
}
else
{
Label2.Text = "注册失败!";
}
// labcontent.Text = "您的用户名是 :"+username.Text;
// Label1.Text = "您的密码是 :"+password.Text;
}
</script>
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = sql;
command.Parameters.AddWithValue("@EditorId", EditorId);
connection.Open();
result = Convert.ToInt32(command.ExecuteScalar());
connection.Close();
}
lz自己对着看把
行 18: sqlcommand.Connection = sqlconnection;
行 19: sqlcommand.CommandText = "insert into ueserInfo (username,psw) values('" + this.username.Text + "','" +this. password.Text + "') ";
行 20: int result = sqlcommand.ExecuteNonQuery();
行 21: //sqlconnection.Close();
行 22: if (result == 1)
protected void butsubmit_click(object sender, EventArgs e)
{
int result=0;
string sqlconnstr = "Data Source=.;Initial Catalog=chapter;Integrated Security=True" ;
using(SqlConnection sqlconnection=new SqlConnection(sqlconnstr))
{
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = sqlconnection;
sqlcommand.CommandText = "insert into ueserInfo (username,psw) values('" + this.username.Text + "','" +this. password.Text + "') ";
result = sqlcommand.ExecuteNonQuery();
}
if (result == 1)
{
Label2.Text="注册成功!";
labcontent.Text = "您的用户名是 :" + username.Text;
Label1.Text = "您的密码是 :" + password.Text;
}
else
{
Label2.Text = "注册失败!";
}
// labcontent.Text = "您的用户名是 :"+username.Text;
// Label1.Text = "您的密码是 :"+password.Text;
}
protected void butsubmit_click(object sender, EventArgs e)
{
int result=0;
string sqlconnstr = "Data Source=.;Initial Catalog=chapter;Integrated Security=True" ;
using(SqlConnection sqlconnection=new SqlConnection(sqlconnstr))
{
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = sqlconnection;
sqlcommand.CommandText = "insert into ueserInfo (username,psw) values('" + this.username.Text + "','" +this. password.Text + "') ";
sqlconnection.Open() //sorry 更正一下
result = sqlcommand.ExecuteNonQuery();
}
if (result == 1)
{
Label2.Text="注册成功!";
labcontent.Text = "您的用户名是 :" + username.Text;
Label1.Text = "您的密码是 :" + password.Text;
}
else
{
Label2.Text = "注册失败!";
}
// labcontent.Text = "您的用户名是 :"+username.Text;
// Label1.Text = "您的密码是 :"+password.Text;
}
sqlconnection.open();