日期:2014-05-17 浏览次数:21095 次
//写个操作数据库函数
public int ExecuteSql(string SQLString)
{
string connectionString = "Data Source=192.168.xx.xx;Initial Catalog=xx;User ID=xx;Pwd=xx";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.SqlClient.SqlException E)
{
connection.Close();
throw new Exception(E.Message);
}
}
}
}
//调用
string sql=string.Format("select * from xx");
ExecuteSql(sql);
using System;
using System.Collections.Generic;
using System.Text;
using S