public string GetData()
{
try
{
SqlConnection sqlConnection =
new SqlConnection(
"Data Source=127.0.0.1;Initial Catalog=SalesERPDB;Integrated Security=True;User Id=sa;Password=123456");
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "select FirstName from TblEmployee";
return sqlCommand.ExecuteScalar().ToString();
}
catch (Exception ex)
{
return ex.ToString();
}
}
C#连接SQLServer数据库
最新推荐文章于 2023-05-09 18:00:00 发布
本文介绍了一个使用C#连接SQL Server并从数据库中获取特定数据的简单示例。示例展示了如何设置数据库连接、执行SQL查询以及处理查询结果。
3643

被折叠的 条评论
为什么被折叠?



