本文整理汇总了C#中System.Data.SqlClient.SqlParameterCollection.AddWithValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlParameterCollection.AddWithValue方法的具体用法?C# SqlParameterCollection.AddWithValue怎么用?C# SqlParameterCollection.AddWithValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlParameterCollection
的用法示例。
在下文中一共展示了SqlParameterCollection.AddWithValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PersistAddExtraParameters
public override void PersistAddExtraParameters(SqlParameterCollection parameters, Employee employee)
{
var emp = employee as EmployeePartTime;
if (emp != null)
{
parameters.AddWithValue("@HourlyPay", emp.HourlyPay);
parameters.AddWithValue("@HoursWorked", emp.HoursWorked);
}
}
示例2: PersistAddExtraParameters
public override void PersistAddExtraParameters(SqlParameterCollection parameters, Employee employee)
{
var emp = employee as EmployeeFullTime;
if (emp != null)
{
parameters.AddWithValue("@AnnualSalary", emp.AnnualSalary);
}
}
示例3: ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien
public static void ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien(DataRow RMucLucChiTieu, DataTable dtDauKy, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
String strDSTruong = "sKyHieu,sTen,sThuyetMinh";
String sXauNoiMa = "";
String[] arrDSTruong = strDSTruong.Split(',');
if (Params.IndexOf("@iID_MaChiTieu") >= 0)
{
Params["@iID_MaChiTieu"].Value = RMucLucChiTieu["iID_MaChiTieu"];
Params["@iID_MaChiTieu_Cha"].Value = RMucLucChiTieu["iID_MaChiTieu_Cha"];
Params["@bLaHangCha"].Value = RMucLucChiTieu["bLaHangCha"];
}
else
{
Params.AddWithValue("@iID_MaChiTieu", RMucLucChiTieu["iID_MaChiTieu"]);
Params.AddWithValue("@iID_MaChiTieu_Cha", RMucLucChiTieu["iID_MaChiTieu_Cha"]);
Params.AddWithValue("@bLaHangCha", RMucLucChiTieu["bLaHangCha"]);
}
String iID_MaChiTieu = Convert.ToString(RMucLucChiTieu["iID_MaChiTieu"]);
String iID_MaChiTieu1 = "";
for (int i = 0; i < dtDauKy.Rows.Count; i++)
{
iID_MaChiTieu1 = Convert.ToString(dtDauKy.Rows[i]["iID_MaChiTieu"]);
if (iID_MaChiTieu.Equals(iID_MaChiTieu1))
{
if (Params.IndexOf("@rSoDauNam") >= 0)
{
Params["@rSoDauNam"].Value = dtDauKy.Rows[i]["rSoCuoiNam"];
}
else
{
Params.AddWithValue("@rSoDauNam", dtDauKy.Rows[i]["rSoCuoiNam"]);
}
dtDauKy.Rows.RemoveAt(i);
break;
}
}
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucChiTieu[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucChiTieu[arrDSTruong[i]]);
}
if (i < arrDSTruong.Length - 1 && String.IsNullOrEmpty(Convert.ToString(RMucLucChiTieu[arrDSTruong[i]])) == false)
{
if (sXauNoiMa != "") sXauNoiMa += "-";
sXauNoiMa += Convert.ToString(RMucLucChiTieu[arrDSTruong[i]]);
}
}
if (Params.IndexOf("@sXauNoiMa") >= 0)
{
Params["@sXauNoiMa"].Value = sXauNoiMa;
}
else
{
Params.AddWithValue("@sXauNoiMa", sXauNoiMa);
}
}
示例4: SetParameter
static void SetParameter(IEdmFunction func, JObject parameterValues, IEdmType edmType, SqlParameterCollection pars)
{
if (parameterValues == null)
return;
JToken token = null;
Type colType = null;
foreach (var p in func.Parameters)
{
if (parameterValues.TryGetValue(p.Name, out token))
{
if (p.Type.Definition.TypeKind == EdmTypeKind.Complex)
{
DataTable dt = new DataTable();
var c = p.Type.AsComplex();
foreach (var item in c.StructuralProperties())
{
dt.Columns.Add(item.Name, item.Type.PrimitiveKind().ToClrType());
}
foreach (var item in token)
{
DataRow dr = dt.NewRow();
foreach (JProperty col in item)
{
if (!dt.Columns.Contains(col.Name))
continue;
colType = dt.Columns[col.Name].DataType;
if (colType == typeof(Boolean))
{
dr.SetField(col.Name, col.Value.ToString() == "0" ? false : true);
}
else
dr.SetField(col.Name, col.Value.ToString().ChangeType(colType));
}
dt.Rows.Add(dr);
}
pars.AddWithValue(p.Name, dt);
}
else
{
if (string.IsNullOrEmpty(token.ToString()))
pars.AddWithValue(p.Name, DBNull.Value);
else
pars.AddWithValue(p.Name, token.ToString().ChangeType(p.Type.PrimitiveKind()));
}
}
}
if (edmType.TypeKind == EdmTypeKind.Entity)
{
foreach (var outp in (edmType as EdmEntityType).Properties())
{
if (outp.Name == "$Results")
continue;
if (pars.Contains(outp.Name))
{
pars[outp.Name].Direction = ParameterDirection.Output;
}
else
{
pars.AddWithValue(outp.Name, DBNull.Value);
}
}
}
}
示例5: ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien
public static void ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien(DataRow RMucLucChiTieu, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
String strDSTruong = "iID_MaDoanhNghiep,sTenDoanhNghiep";
String[] arrDSTruong = strDSTruong.Split(',');
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucChiTieu[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucChiTieu[arrDSTruong[i]]);
}
}
}
示例6: ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien
public static void ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien(DataRow RMucLucChiTieu, DataTable dtDauKy, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
String strDSTruong = "sKyHieu,sTen,sMaSoBangCanDoi";
String[] arrDSTruong = strDSTruong.Split(',');
if (Params.IndexOf("@iID_MaChiTieuHoSo") >= 0)
{
Params["@iID_MaChiTieuHoSo"].Value = RMucLucChiTieu["iID_MaChiTieuHoSo"];
Params["@iID_MaChiTieuHoSo_Cha"].Value = RMucLucChiTieu["iID_MaChiTieuHoSo_Cha"];
Params["@bLaHangCha"].Value = RMucLucChiTieu["bLaHangCha"];
}
else
{
Params.AddWithValue("@iID_MaChiTieuHoSo", RMucLucChiTieu["iID_MaChiTieuHoSo"]);
Params.AddWithValue("@iID_MaChiTieuHoSo_Cha", RMucLucChiTieu["iID_MaChiTieuHoSo_Cha"]);
Params.AddWithValue("@bLaHangCha", RMucLucChiTieu["bLaHangCha"]);
}
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucChiTieu[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucChiTieu[arrDSTruong[i]]);
}
}
//Lấy dữ liệu từ quý trước
String iID_MaChiTieu = Convert.ToString(RMucLucChiTieu["iID_MaChiTieuHoSo"]);
String iID_MaChiTieu1 = "";
for (int i = 0; i < dtDauKy.Rows.Count; i++)
{
iID_MaChiTieu1 = Convert.ToString(dtDauKy.Rows[i]["iID_MaChiTieuHoSo"]);
if (iID_MaChiTieu.Equals(iID_MaChiTieu1))
{
if (Params.IndexOf("@rKyTruocChuyenSang") >= 0)
{
Params["@rKyTruocChuyenSang"].Value = dtDauKy.Rows[i]["rSoConNoCuoiKy"];
}
else
{
Params.AddWithValue("@rKyTruocChuyenSang", dtDauKy.Rows[i]["rSoConNoCuoiKy"]);
}
dtDauKy.Rows.RemoveAt(i);
break;
}
}
//End Lấy dữ liệu từ quý trước
}
示例7: AddWithValue
internal static SqlParameter AddWithValue(SqlParameterCollection parameters, string paramName, string paramValue)
{
#if NETv2_0
return parameters.AddWithValue(paramName, paramValue);
#else
return parameters.Add(paramName, paramValue);
#endif
}
示例8: ThemThongTinCuaMucLucNganSach
public static void ThemThongTinCuaMucLucNganSach(DataRow RMucLucNganSach, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
//String[] arrDSDuocNhapTruongTien = MucLucNganSachModels.strDSDuocNhapTruongTien.Split(',');
String[] arrDSTruong = MucLucNganSachModels.strDSTruong.Split(',');
String sXauNoiMa = "";
if (Params.IndexOf("@iID_MaMucLucNganSach") >= 0)
{
Params["@iID_MaMucLucNganSach"].Value = RMucLucNganSach["iID_MaMucLucNganSach"];
Params["@iID_MaMucLucNganSach_Cha"].Value = RMucLucNganSach["iID_MaMucLucNganSach_Cha"];
Params["@bLaHangCha"].Value = RMucLucNganSach["bLaHangCha"];
}
else
{
Params.AddWithValue("@iID_MaMucLucNganSach", RMucLucNganSach["iID_MaMucLucNganSach"]);
Params.AddWithValue("@iID_MaMucLucNganSach_Cha", RMucLucNganSach["iID_MaMucLucNganSach_Cha"]);
Params.AddWithValue("@bLaHangCha", RMucLucNganSach["bLaHangCha"]);
}
//for (int i = 0; i < arrDSDuocNhapTruongTien.Length; i++)
//{
// if (Params.IndexOf("@" + arrDSDuocNhapTruongTien[i]) >= 0)
// {
// Params["@" + arrDSDuocNhapTruongTien[i]].Value = RMucLucNganSach[arrDSDuocNhapTruongTien[i]];
// }
// else
// {
// Params.AddWithValue("@" + arrDSDuocNhapTruongTien[i], RMucLucNganSach[arrDSDuocNhapTruongTien[i]]);
// }
//}
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucNganSach[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucNganSach[arrDSTruong[i]]);
}
if (i < arrDSTruong.Length - 1 && String.IsNullOrEmpty(Convert.ToString(RMucLucNganSach[arrDSTruong[i]])) == false)
{
if (sXauNoiMa != "") sXauNoiMa += "-";
sXauNoiMa += Convert.ToString(RMucLucNganSach[arrDSTruong[i]]);
}
}
if (Params.IndexOf("@sXauNoiMa") >= 0)
{
Params["@sXauNoiMa"].Value = sXauNoiMa;
}
else
{
Params.AddWithValue("@sXauNoiMa", sXauNoiMa);
}
}
示例9: ThemThongTinMucLucNganSach_CoTruongTien
public static void ThemThongTinMucLucNganSach_CoTruongTien(DataRow RMucLucNganSach, SqlParameterCollection Params,DataTable dt,Boolean DonViChoPhanBo=false)
{
//<--Thêm tham số từ bảng MucLucNganSach
String[] arrDSDuocNhapTruongTien = MucLucNganSachModels.strDSDuocNhapTruongTien.Split(',');
String[] arrDSTruong = MucLucNganSachModels.strDSTruong.Split(',');
String[] arrTruongTienSo = MucLucNganSachModels.strDSTruongTien_So.Split(',');
String sXauNoiMa = "";
if (Params.IndexOf("@iID_MaMucLucNganSach") >= 0)
{
Params["@iID_MaMucLucNganSach"].Value = RMucLucNganSach["iID_MaMucLucNganSach"];
Params["@iID_MaMucLucNganSach_Cha"].Value = RMucLucNganSach["iID_MaMucLucNganSach_Cha"];
Params["@bLaHangCha"].Value = RMucLucNganSach["bLaHangCha"];
}
else
{
Params.AddWithValue("@iID_MaMucLucNganSach", RMucLucNganSach["iID_MaMucLucNganSach"]);
Params.AddWithValue("@iID_MaMucLucNganSach_Cha", RMucLucNganSach["iID_MaMucLucNganSach_Cha"]);
Params.AddWithValue("@bLaHangCha", RMucLucNganSach["bLaHangCha"]);
}
for (int i = 0; i < arrDSDuocNhapTruongTien.Length; i++)
{
if (Params.IndexOf("@" + arrDSDuocNhapTruongTien[i]) >= 0)
{
Params["@" + arrDSDuocNhapTruongTien[i]].Value = RMucLucNganSach[arrDSDuocNhapTruongTien[i]];
}
else
{
Params.AddWithValue("@" + arrDSDuocNhapTruongTien[i], RMucLucNganSach[arrDSDuocNhapTruongTien[i]]);
}
}
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucNganSach[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucNganSach[arrDSTruong[i]]);
}
if (i < arrDSTruong.Length - 1 && String.IsNullOrEmpty(Convert.ToString(RMucLucNganSach[arrDSTruong[i]])) == false)
{
if (sXauNoiMa != "") sXauNoiMa += "-";
sXauNoiMa += Convert.ToString(RMucLucNganSach[arrDSTruong[i]]);
}
}
if (DonViChoPhanBo==false)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
string sXauNoiMa1 = Convert.ToString(dt.Rows[j]["sXauNoiMa"]);
if (sXauNoiMa == sXauNoiMa1)
{
for (int i = 0; i < arrTruongTienSo.Length; i++)
{
if (Params.IndexOf("@" + arrTruongTienSo[i]) >= 0)
{
Params["@" + arrTruongTienSo[i]].Value = dt.Rows[j][arrTruongTienSo[i]];
Params["@" + arrTruongTienSo[i]+"_ChiTieu"].Value = dt.Rows[j][arrTruongTienSo[i]];
}
else
{
Params.AddWithValue("@" + arrTruongTienSo[i], dt.Rows[j][arrTruongTienSo[i]]);
Params.AddWithValue("@" + arrTruongTienSo[i] + "_ChiTieu", dt.Rows[j][arrTruongTienSo[i]]);
}
}
break;
}
else
{
for (int i = 0; i < arrTruongTienSo.Length; i++)
{
if (Params.IndexOf("@" + arrTruongTienSo[i]) >= 0)
{
Params["@" + arrTruongTienSo[i]].Value = 0;
Params["@" + arrTruongTienSo[i] + "_ChiTieu"].Value = 0;
}
else
{
Params.AddWithValue("@" + arrTruongTienSo[i], 0);
Params.AddWithValue("@" + arrTruongTienSo[i]+"_ChiTieu", 0);
}
}
}
}
}
else
{
for (int i = 0; i < arrTruongTienSo.Length; i++)
{
if (Params.IndexOf("@" + arrTruongTienSo[i]) >= 0)
{
Params["@" + arrTruongTienSo[i]].Value =Convert.ToInt64(RMucLucNganSach[arrTruongTienSo[i]+"_DuToan"])*(-1);
// Params["@" + arrTruongTienSo[i]].Value = 0;
Params["@" + arrTruongTienSo[i]+"_ChiTieu"].Value = 0;
}
else
{
Params.AddWithValue("@" + arrTruongTienSo[i], Convert.ToInt64(RMucLucNganSach[arrTruongTienSo[i]+"_DuToan"])*(-1));
//.........这里部分代码省略.........
示例10: ThemThongTinChiTiet
public static void ThemThongTinChiTiet(DataRow RMucLucChiTieu,DataTable dtNamTruoc, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
String strDSTruong = "iID_MaDoanhNghiep,sTenDoanhNghiep";
String[] arrDSTruong = strDSTruong.Split(',');
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucChiTieu[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucChiTieu[arrDSTruong[i]]);
}
}
String iID_MaDoanhNghiep = Convert.ToString(RMucLucChiTieu["iID_MaDoanhNghiep"]);
String iID_MaDoanhNghiep1 = "";
for (int i = 0; i < dtNamTruoc.Rows.Count; i++)
{
iID_MaDoanhNghiep1 =Convert.ToString(dtNamTruoc.Rows[i]["iID_MaDoanhNghiep"]);
if (iID_MaDoanhNghiep.Equals(iID_MaDoanhNghiep1))
{
for (int j = 0; j < arrDanhSachTruongTien_NT.Length; j++)
{
if (Params.IndexOf("@" + arrDanhSachTruongTien_NT[i]) >= 0)
{
Params["@" + arrDanhSachTruongTien_NT[i]].Value = dtNamTruoc.Rows[i][arrDSTruong[j]];
}
else
{
Params.AddWithValue("@" + arrDanhSachTruongTien_NT[i], dtNamTruoc.Rows[i][arrDSTruong[j]]);
}
}
dtNamTruoc.Rows.RemoveAt(i);
break;
}
}
}
示例11: AddCommandParamIfRequired
private void AddCommandParamIfRequired(SqlParameterCollection sqlParameterCollection, string dbFieldName, object value)
{
if (!ShouldAddDbField(dbFieldName))
return;
sqlParameterCollection.AddWithValue("@" + dbFieldName, value ?? DBNull.Value);
}
示例12: ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien
public static void ThemThongTinChiTietTaiChinhDoanhNghiepLayTruongTien(DataRow RMucLucChiTieu, SqlParameterCollection Params)
{
//<--Thêm tham số từ bảng MucLucNganSach
String strDSTruong = "sKyHieu,sTen,sDonViTinh";
String sXauNoiMa = "";
String[] arrDSTruong = strDSTruong.Split(',');
if (Params.IndexOf("@iID_MaChiTieuHoSo") >= 0)
{
Params["@iID_MaChiTieuHoSo"].Value = RMucLucChiTieu["iID_MaChiTieuHoSo"];
Params["@iID_MaChiTieuHoSo_Cha"].Value = RMucLucChiTieu["iID_MaChiTieuHoSo_Cha"];
Params["@bLaHangCha"].Value = RMucLucChiTieu["bLaHangCha"];
}
else
{
Params.AddWithValue("@iID_MaChiTieuHoSo", RMucLucChiTieu["iID_MaChiTieuHoSo"]);
Params.AddWithValue("@iID_MaChiTieuHoSo_Cha", RMucLucChiTieu["iID_MaChiTieuHoSo_Cha"]);
Params.AddWithValue("@bLaHangCha", RMucLucChiTieu["bLaHangCha"]);
}
for (int i = 0; i < arrDSTruong.Length; i++)
{
if (Params.IndexOf("@" + arrDSTruong[i]) >= 0)
{
Params["@" + arrDSTruong[i]].Value = RMucLucChiTieu[arrDSTruong[i]];
}
else
{
Params.AddWithValue("@" + arrDSTruong[i], RMucLucChiTieu[arrDSTruong[i]]);
}
if (i < arrDSTruong.Length - 1 && String.IsNullOrEmpty(Convert.ToString(RMucLucChiTieu[arrDSTruong[i]])) == false)
{
if (sXauNoiMa != "") sXauNoiMa += "-";
sXauNoiMa += Convert.ToString(RMucLucChiTieu[arrDSTruong[i]]);
}
}
if (Params.IndexOf("@sXauNoiMa") >= 0)
{
Params["@sXauNoiMa"].Value = sXauNoiMa;
}
else
{
Params.AddWithValue("@sXauNoiMa", sXauNoiMa);
}
}
示例13: setCommandParameters
public static void setCommandParameters(ref SqlParameterCollection sqlParameterCollection, ref string sqlstr, string[] values)
{
string[] paramNames = values.Select((s, i) => "@param" + i.ToString()).ToArray();
for (int i = 0; i < paramNames.Length; i++)
{
sqlParameterCollection.AddWithValue(paramNames[i], values[i]);
}
string inClause = string.Join(",", paramNames);
sqlstr = string.Format(sqlstr, inClause);
}