如何停止未创建条目的条目 [英] how to stop the entries in which the entries are not made
本文介绍了如何停止未创建条目的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class Admin_CreateDocket:System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ amitpandeyConnectionString]。ConnectionString);
受保护 void Page_Load( object sender,EventArgs e)
{
con.Open();
}
受保护 void Button1_Click( object sender,EventArgs e)
{
SqlCommand cmd = new SqlCommand( 插入CreateDocket值(' + Branch_Code.Text + ',' + Date_Time.Text + ',' + Sr_No.Text + ',' + Docket_No.Text + ',' + Pin_Code.Text + ',' + Basis.SelectedItem + ',' + To.Text + ',' + Conr_Code.Text + ',' + Consignee.Text + ',' + PKTS.Text + ',' + Act_Wt.Text + ',' + Charge_Wt.Text + ',' + Grand_Total.Text + ',' + Goods_Type.Text + ',' + COD_Amount.Text + '),con);
SqlCommand amd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No1.Text + ',' + Docket_No1.Text + ',' + Pin_Code1.Text + ',' + Basis1.SelectedItem + ',' + To1.Text + ',' + Conr_Code1.Text + ',' + Consignee1.Text + ',' + PKTS1.Text + ',' + Act_Wt1.Text + ',' + Charge_Wt1.Text + ',' + Grand_Total1.Text + ',' + Goods_Type1.Text + ',' + COD_Amount1.Text + '),con);
SqlCommand bmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No2.Text + ',' + Docket_No2.Text + ',' + Pin_Code2.Text + ',' + Basis2.SelectedItem + ',' + To2.Text + ',' + Conr_Code2.Text + ',' + Consignee2.Text + ',' + PKTS2.Text + ',' + Act_Wt2.Text + ',' + Charge_Wt2.Text + ',' + Grand_Total2.Text + ',' + Goods_Type2.Text + ',' + COD_Amount2.Text + '),con);
SqlCommand dmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No3.Text + ',' + Docket_No3.Text + ',' + Pin_Code3.Text + ',' + Basis3.SelectedItem + ',' + To.3Text + ',' + Conr_Code3.Text + ',' + Consignee3.Text + ',' + PKTS3.Text + ',' + Act_Wt3.Text + ',' + Charge_Wt3.Text + ',' + Grand_Total3.Text + ',' + Goods_Type3.Text + ',' + COD_Amount3.Text + '),con);
SqlCommand emd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No4.Text + ',' + Docket_No4.Text + ',' + Pin_Code4.Text + ',' + Basis4.SelectedItem + ',' + To4.Text + ',' + Conr_Code4.Text + ',' + Consignee4.Text + ',' + PKTS4.Text + ',' + Act_Wt4.Text + ',' + Charge_Wt4.Text + ',' + Grand_Total4.Text + ',' + Goods_Type4.Text + ',' + COD_Amount4.Text + '),con);
SqlCommand fmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No5.Text + ',' + Docket_No5.Text + ',' + Pin_Code5.Text + ',' + Basis5.SelectedItem + ',' + To5.Text + ',' + Conr_Code5.Text + ',' + Consignee5.Text + ',' + PKTS5.Text + ',' + Act_Wt5.Text + ',' + Charge_Wt5.Text + ',' + Grand_Total5.Text + ',' + Goods_Type5.Text + ',' + COD_Amount5.Text + '),con);
SqlCommand gmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No6.Text + ',' + Docket_No6.Text + ',' + Pin_Code6.Text + ',' + Basis6.SelectedItem + ',' + To6.Text + ',' + Conr_Code6.Text + ',' + Consignee6.Text + ',' + PKTS6.Text + ',' + Act_Wt6.Text + ',' + Charge_Wt6.Text + ',' + Grand_Total6.Text + ',' + Goods_Type6.Text + ',' + COD_Amount6.Text + '),con);
SqlCommand hmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No7.Text + ',' + Docket_No7.Text + ',' + Pin_Code7.Text + ',' + Basis7.SelectedItem + ',' + To7.Text + ',' + Conr_Code7.Text + ',' + Consignee7.Text + ',' + PKTS7.Text + ',' + Act_Wt7.Text + ',' + Charge_Wt7.Text + ',' + Grand_Total7.Text + ',' + Goods_Type7.Text + ',' + COD_Amount7.Text + '),con);
SqlCommand imd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No8.Text + ',' + Docket_No8.Text + ',' + Pin_Code8.Text + ',' + Basis8.SelectedItem + ',' + To8.Text + ',' + Conr_Code8.Text + ',' + Consignee8.Text + ',' + PKTS8.Text + ',' + Act_Wt8.Text + ',' + Charge_Wt8.Text + ',' + Grand_Total8.Text + ',' + Goods_Type8.Text + ',' + COD_Amount8.Text + '),con);
SqlCommand jmd = new SqlCommand( insert到CreateDocket值(' + Branch_Code.Text + ',' + Date_Time .Text + ',' + Sr_No9.Text + ',' + Docket_No9.Text + ',' + Pin_Code9.Text + ',' + Basis9.SelectedItem + ',' + To9.Text + ',' + Conr_Code9.Text + ',' + Consignee9.Text + ',' + PKTS9.Text + ',' + Act_Wt9.Text + ',' + Charge_Wt9.Text + ',' + Grand_Total9.Text + ',' + Goods_Type9.Text + ',' + COD_Amount9.Text + '),con);
cmd.ExecuteNonQuery();
amd.ExecuteNonQuery();
bmd.ExecuteNonQuery();
dmd.ExecuteNonQuery();
emd.ExecuteNonQuery();
fmd.ExecuteNonQuery();
gmd.ExecuteNonQuery();
hmd.ExecuteNonQuery();
imd.ExecuteNonQuery();
jmd.ExecuteNonQuery();
con.Close();
i这里有10行,用户一次可以输入10行。但问题是如果用户只需要输入2行行,然后其余的行取0值并保存在数据库中,我不希望请帮助我。
解决方案
我会创建单独的类例如,实体(此处示例仅包含两列,您可以相应地更新它)
// 为您的权利创建类
public class Docket
{
public string Branch_Code { get ; set ; }
public string Sr_No { get 跨度>; set ; }
// 定义所有属性
public bool IsValid()
{
// 包括所有必填字段
return string .IsNullOrWhiteSpace(Branch_Code)||
string .IsNullOrWhiteSpace(Sr_No);
}
}
数据库操作可以由另一个类单独处理
public class DBHandler
{
public bool InsertDocket(Docket docket)
{
bool succsess = false ;在插入检查数据验证之前
//
// 如果数据可以插入,则继续
if (docket.IsValid())
{
使用(SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ amitpandeyConnectionString]。ConnectionString))
使用(SqlCommand cmd = new SqlCommand( 插入CreateDocket(Branch_Code,Sr_No)值(@ Branch_Code,@ Sr_No),con))
{
cmd.Parameters.AddWithValue( @ Branch_Code,docket.Branch_Code);
cmd.Parameters.AddWithValue( @ Sr_No,docket.Branch_Code);
con.Open();
cmd.ExecuteNonQuery();
succsess = true ;
}
}
return succsess;
}
}
以上方法可以从用户界面拨打
DBHandler dBHandler = new DBHandler();
dBHandler.InsertDocket( new Docket(){Branch_Code = Branch_Code.Text,Sr_No = Sr_No.Text});
dBHandler.InsertDocket( new Docket(){Branch_Code = Branch_Code.Text,Sr_No = Sr_No1.Text});
public partial class Admin_CreateDocket : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amitpandeyConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No.Text + "','" + Docket_No.Text + "','" + Pin_Code.Text + "','"+Basis.SelectedItem+"','" + To.Text + "','" + Conr_Code.Text + "','" + Consignee.Text + "','" + PKTS.Text + "','" + Act_Wt.Text + "','" + Charge_Wt.Text + "','" + Grand_Total.Text + "','" + Goods_Type.Text + "','" + COD_Amount.Text + "')", con);
SqlCommand amd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No1.Text + "','" + Docket_No1.Text + "','" + Pin_Code1.Text + "','" + Basis1.SelectedItem + "','" + To1.Text + "','" + Conr_Code1.Text + "','" + Consignee1.Text + "','" + PKTS1.Text + "','" + Act_Wt1.Text + "','" + Charge_Wt1.Text + "','" + Grand_Total1.Text + "','" + Goods_Type1.Text + "','" + COD_Amount1.Text + "')", con);
SqlCommand bmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No2.Text + "','" + Docket_No2.Text + "','" + Pin_Code2.Text + "','" + Basis2.SelectedItem + "','" + To2.Text + "','" + Conr_Code2.Text + "','" + Consignee2.Text + "','" + PKTS2.Text + "','" + Act_Wt2.Text + "','" + Charge_Wt2.Text + "','" + Grand_Total2.Text + "','" + Goods_Type2.Text + "','" + COD_Amount2.Text + "')", con);
SqlCommand dmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No3.Text + "','" + Docket_No3.Text + "','" + Pin_Code3.Text + "','" + Basis3.SelectedItem + "','" + To3.Text + "','" + Conr_Code3.Text + "','" + Consignee3.Text + "','" + PKTS3.Text + "','" + Act_Wt3.Text + "','" + Charge_Wt3.Text + "','" + Grand_Total3.Text + "','" + Goods_Type3.Text + "','" + COD_Amount3.Text + "')", con);
SqlCommand emd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No4.Text + "','" + Docket_No4.Text + "','" + Pin_Code4.Text + "','" + Basis4.SelectedItem + "','" + To4.Text + "','" + Conr_Code4.Text + "','" + Consignee4.Text + "','" + PKTS4.Text + "','" + Act_Wt4.Text + "','" + Charge_Wt4.Text + "','" + Grand_Total4.Text + "','" + Goods_Type4.Text + "','" + COD_Amount4.Text + "')", con);
SqlCommand fmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No5.Text + "','" + Docket_No5.Text + "','" + Pin_Code5.Text + "','" + Basis5.SelectedItem + "','" + To5.Text + "','" + Conr_Code5.Text + "','" + Consignee5.Text + "','" + PKTS5.Text + "','" + Act_Wt5.Text + "','" + Charge_Wt5.Text + "','" + Grand_Total5.Text + "','" + Goods_Type5.Text + "','" + COD_Amount5.Text + "')", con);
SqlCommand gmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No6.Text + "','" + Docket_No6.Text + "','" + Pin_Code6.Text + "','" + Basis6.SelectedItem + "','" + To6.Text + "','" + Conr_Code6.Text + "','" + Consignee6.Text + "','" + PKTS6.Text + "','" + Act_Wt6.Text + "','" + Charge_Wt6.Text + "','" + Grand_Total6.Text + "','" + Goods_Type6.Text + "','" + COD_Amount6.Text + "')", con);
SqlCommand hmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No7.Text + "','" + Docket_No7.Text + "','" + Pin_Code7.Text + "','" + Basis7.SelectedItem + "','" + To7.Text + "','" + Conr_Code7.Text + "','" + Consignee7.Text + "','" + PKTS7.Text + "','" + Act_Wt7.Text + "','" + Charge_Wt7.Text + "','" + Grand_Total7.Text + "','" + Goods_Type7.Text + "','" + COD_Amount7.Text + "')", con);
SqlCommand imd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No8.Text + "','" + Docket_No8.Text + "','" + Pin_Code8.Text + "','" + Basis8.SelectedItem + "','" + To8.Text + "','" + Conr_Code8.Text + "','" + Consignee8.Text + "','" + PKTS8.Text + "','" + Act_Wt8.Text + "','" + Charge_Wt8.Text + "','" + Grand_Total8.Text + "','" + Goods_Type8.Text + "','" + COD_Amount8.Text + "')", con);
SqlCommand jmd = new SqlCommand("insert into CreateDocket values('" + Branch_Code.Text + "','" + Date_Time.Text + "','" + Sr_No9.Text + "','" + Docket_No9.Text + "','" + Pin_Code9.Text + "','" + Basis9.SelectedItem + "','" + To9.Text + "','" + Conr_Code9.Text + "','" + Consignee9.Text + "','" + PKTS9.Text + "','" + Act_Wt9.Text + "','" + Charge_Wt9.Text + "','" + Grand_Total9.Text + "','" + Goods_Type9.Text + "','" + COD_Amount9.Text + "')", con);
cmd.ExecuteNonQuery();
amd.ExecuteNonQuery();
bmd.ExecuteNonQuery();
dmd.ExecuteNonQuery();
emd.ExecuteNonQuery();
fmd.ExecuteNonQuery();
gmd.ExecuteNonQuery();
hmd.ExecuteNonQuery();
imd.ExecuteNonQuery();
jmd.ExecuteNonQuery();
con.Close();
i have here 10 rows the user can enter 10 rows at a time .but the problem is if theuser has to enter only 2 rows ,then the rest of the rows are taking 0 value and saving in database which I don't want pls help me.
解决方案
I would create separate class for the entity, for example ( here example having two columns only, you may update it accordingly)
//create class for your entitiy public class Docket { public string Branch_Code { get; set; } public string Sr_No { get; set; } //define all the properties public bool IsValid() { // include all mandatory fields return string.IsNullOrWhiteSpace(Branch_Code) || string.IsNullOrWhiteSpace(Sr_No); } }
database operation can be separately handled by another class
public class DBHandler { public bool InsertDocket(Docket docket) { bool succsess = false; // before insert check for data validation // if data OK to insert, then continue if (docket.IsValid()) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["amitpandeyConnectionString"].ConnectionString)) using (SqlCommand cmd = new SqlCommand("insert into CreateDocket (Branch_Code, Sr_No) values (@Branch_Code, @Sr_No)", con)) { cmd.Parameters.AddWithValue("@Branch_Code", docket.Branch_Code); cmd.Parameters.AddWithValue("@Sr_No", docket.Branch_Code); con.Open(); cmd.ExecuteNonQuery(); succsess = true; } } return succsess; } }
Above method can call from the UI
DBHandler dBHandler = new DBHandler(); dBHandler.InsertDocket(new Docket() { Branch_Code = Branch_Code.Text, Sr_No = Sr_No.Text }); dBHandler.InsertDocket(new Docket() { Branch_Code = Branch_Code.Text, Sr_No = Sr_No1.Text });
这篇关于如何停止未创建条目的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文