DbHelper-SQL????????????
???????????? ???????[ 2014/6/17 13:12:47 ] ????????DbHelper-SQL ?????
using System;
using System.Data;
using System.Data.SqlClient;
namespace Whir.Software.Framework.Ultimate
{
/// <summary>
/// ?????????????
/// </summary>
public class DbHelper
{
#region ?ж??????????
/// <summary>
/// ?ж????????????
/// </summary>
/// <param name="con"> ?????????</param>
/// <returns>true ???????????false??????????</returns>
public static bool IsConnected(string con)
{
bool flag;
var conn = new SqlConnection(con);
try
{
conn.Open();
flag = true;
}
catch (Exception)
{
flag = false;
}
finally
{
conn.Close();
}
return flag;
}
#endregion
#region ??в???????sql???
/// <summary>
/// ??в???????sql???
/// </summary>
/// <param name="sql">?????????sql???</param>
/// <param name="con"></param>
/// <returns>??????????????</returns>
public static bool Execute(string sql?? string con)
{
var cmd = new SqlCommand();
var connection = new SqlConnection(con);
try
{
using (connection)
{
cmd.Connection = connection;
cmd.CommandText = sql;
connection.Open();
cmd.ExecuteNonQuery();
return true;
}
}
catch (Exception)
{
return false;
}
}
#endregion
#region ???SQL?????DataTable
/// <summary>
/// ???SQL?????DataTable
/// </summary>
/// <param name="sql"></param>
/// <param name="con"></param>
/// <returns></returns>
public static DataTable ExcuteDataTable(string sql?? string con)
{
var cmd = new SqlCommand();
var connection = new SqlConnection(con);
try
{
using (connection)
{
cmd.Connection = connection;
cmd.CommandText = sql;
connection.Open();
var da = new SqlDataAdapter(cmd);
var ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
}
catch (Exception ex)
{
var dt = new DataTable();
dt.Columns.Add("?????");
DataRow row = dt.NewRow();
row["?????"] = ex.Message;
dt.Rows.Add(row);
return dt;
}
}
#endregion
#region ???SQL????????????
/// <summary>
/// ???SQL????????????
/// </summary>
/// <param name="sql"></param>
/// <param name="con"></param>
/// <returns></returns>
public static object ExecuteScalar(string sql?? string con)
{
var cmd = new SqlCommand();
var connection = new SqlConnection(con);
try
{
using (connection)
{
cmd.Connection = connection;
cmd.CommandText = sql;
connection.Open();
return cmd.ExecuteScalar();
}
}
catch (Exception)
{
return string.Empty;
}
}
#endregion
#region ?????Id
/// <summary>
/// ?????Id
/// </summary>
/// <param name="tableName"></param>
/// <param name="fieldName"></param>
/// <param name="con"></param>
/// <returns></returns>
public static int GetMaxId(string tableName?? string fieldName?? string con)
{
string sql = "SELECT NVL(MAX({0})??0)+1 FROM {1}";
try
{
sql = string.Format(sql?? fieldName?? tableName);
int result;
Int32.TryParse(ExecuteScalar(sql?? con).ToString()?? out result);
return result;
}
catch (Exception)
{
return -1;
}
}
#endregion
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
?????????????????????????Щ????????????????????TC???????????????Щ???????????????????????????????????????????????(java .net ?????)???mysql???????????????????ж????д???Python???????????????(DB2)??????BufferPool????????????????????????????????6??????????????????滮???????????????-????????SQL Server???????????????????λ?????PHP??SQL????????????????????Pythonд???NoSQL????????? SQL ?е????????????? SQL ?е?????????Java???????:?????MySQL???????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????