110,534
社区成员
发帖
与我相关
我的任务
分享
private string strServer = "server=.;database=Client;uid=sa;pwd=sa";
private void button2_Click(object sender, EventArgs e)
{
this.openFileDialog1.ShowDialog();
this.textBox1.Text = this.openFileDialog1.FileName;
}
/// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name="SQLString">SQL语句</param>
/// <returns>影响的记录数</returns>
public int ExecuteNonQuery(string SQLString)
{
using (SqlConnection connection = new SqlConnection(this.strServer ))
{
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 e;
}
}
}
}
private void button3_Click(object sender, EventArgs e)
{
string strSQL = "EXEC master..xp_cmdshell 'Osql -s.-Usa -Psa -i" + this.textBox1.Text .ToString ()+ "'";
try
{
ExecuteNonQuery(strSQL);
}
catch
{
}
}
EXEC master..xp_cmdshell 'Osql -s. -Usa -P你的密码 -iC:\XXX.sql'