向資料庫中插入空值
阿新 • • 發佈:2019-02-08
//修改
private void simpleButton_Update_Click(object sender, EventArgs e)
{
try
{
Client cl = new Client(textEdit_client.Text);
DBHelper db = new DBHelper(cl.ShareConnect);
string sql = string.Format(@"
update [Tb_CompanyConfig] set [email protected],[email protected]
where [email protected] and [email protected] and [email protected] and [email protected]");
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@sheetname",textEdit_sheetName.Text),
new SqlParameter("@importstyle", ModelItemIsNow (textEdit_importstyle.Text)),
new SqlParameter("@code",textEdit_code.Text),
new SqlParameter("@client",textEdit_client.Text),
new SqlParameter("@datatype",textEdit_datatype.Text),
new SqlParameter("@id",drGlobal["id"])
};
int val = db.DBUpdate(sql, para);
if (val > 0)
{
MessageBox.Show("修改成功!共有:" + val + "行受影響。");
this.Close();
drGlobal["sheetname"] = textEdit_sheetName.Text;
drGlobal["importstyle"] = textEdit_importstyle.Text;
}
else
{
MessageBox.Show("修改失敗!");
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 判斷輸入字串是否NULL如果是則向資料庫中插入NULL
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public object ModelItemIsNow(string str)
{
if (str == null || str.ToString().Trim().Length <= 0 || str.ToUpper() == "NULL")
{
return DBNull.Value;
}
else
{
return str;
}
}