4
Answers

How to Insert The 7 Day Records and save in the SqlTable?

Kamala Veni

Kamala Veni

8y
379
1
I am having a form with 10 Columns ,in that i wanna insert data up to next seven days  and Save now itself,
 bt  while am inserting  data,its show oly 7th day record as saved in tha sql table,now it doesnt storing other 6 day records in table.
hw to clear dat ?
 
my code: 
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Name"].ConnectionString; cnn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from tbl_sch1";
cmd.Connection = cnn; SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds, "tbl_sch1");
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataRow drow = ds.Tables["tbl_sch1"].NewRow();
drow["Day"] = lbd.Text;
drow["Time"] = lbb.Text;
drow["Date"] = lb.Text;
drow["blk_1"] = txtb1.Text;
drow["blk_2"] = txtb2.Text;
drow["blk_3"] = txtb3.Text;
drow["blk_4"] = txtb4.Text;
drow["blk_5"] = txtb5.Text;
drow["blk_6"] = txtb6.Text;
drow["blk_7"] = txtb7.Text;
drow["blk_8"] = txtb8.Text;
drow["blk_9"] = txtb9.Text;
drow["blk_10"] = txtb10.Text;
 
Answers (4)
0
Kamala Veni

Kamala Veni

NA 65 9.2k 8y
cmd.CommandText = "select * from tbl_sch1 where blk_1,blk_2,blk_3,blk_4,blk_5,blk_6,blk_7,blk_8,blk_9,blk_10"; i typed like this,bt throw error,i didnt knw how to get pls help me
0
Shubham Kumar

Shubham Kumar

NA 6.5k 260.1k 8y
it just a where condition which is not getting true so your dataset generate blank row and data adapter with stringbuilder always generates insert query for it
0
Kamala Veni

Kamala Veni

NA 65 9.2k 8y
cmd.CommandText="select * from tbl_sch1 where 0=1" in this line wt is 0 =1 mentioning? can u explain clearly
0
Shubham Kumar

Shubham Kumar

NA 6.5k 260.1k 8y
HI,
change the query like this
 
cmd.CommandText="select * from tbl_sch1 where 0=1"
so that the insert command is automatically generated