I got 2 datetimepicker, 1 dropdownlist, 1 gridview, 4 textboxes and 1 button in my asp.net project.
I choose the dates from datetimepicker and i choose the employee name from dropdownlist.
After i get the gridview according to that criterias. After that, i want to enter values in to the textboxes and i want to insert that values into the database with my button1_click event. Or if i can do that on source side.
How can i do that ? Please help.
Waiting your answers.
If you understand what you're doing, you're not learning anything.
Of course i know they are sql parameters.
But i told you. Look at my 1st entry on this page. I have 2 datetimepicker, 1 dropdownlist.
i will choose 2 dates, i will choose the employee and i will enter the values DAY, P1, P2, OVER. After clicking button, i need to insert data, according to this criterias.
Did you understand what i mean ?
Thanks.
If you understand what you're doing, you're not learning anything.
You do not give and answer really, just writing my code against me :)
Sorry but please don't misunderstand, please kindly see my codes——
I've changed your SqlParameters' values——Look at this:I've used Dropdownlist's SelectedValue because as far as I see,It's you that wanna update values from Dropdownlist or other controls' values.
Okay, sorry about that missunderstanding my friend, that's my bad :)
The answer is nearly found.Thanks for your answer. But here is the problem. This commands adds new rows into my table, i need to insert an existing row.
Here something to make your mind clear;
i have penalties table which includes that columuns ;
1 mike out 250 350 100 0 0 200 0 900 - - - - 22-06-2012
2 john in 350 150 200 200 100 0 100 1100 - - - - 28-06-2012
As you see from here my friend, i will choose the dates from my datetimepickers, i will choose the employee from my dropdownlist and i will enter the values into textboxes and after that i will click finish button.
the day,p1,p2 and over values must be inserted into that chosen employee.
waiting your answer please, i need it too badly..
thanks.
If you understand what you're doing, you're not learning anything.
Kuthay Gumus
Member
13 Points
116 Posts
Inserting Data According To Dropdownlist Criteria
Dec 28, 2012 09:30 PM|LINK
Hi,
I got 2 datetimepicker, 1 dropdownlist, 1 gridview, 4 textboxes and 1 button in my asp.net project.
I choose the dates from datetimepicker and i choose the employee name from dropdownlist.
After i get the gridview according to that criterias. After that, i want to enter values in to the textboxes and i want to insert that values into the database with my button1_click event. Or if i can do that on source side.
How can i do that ? Please help.
Waiting your answers.
rimagandhi
Participant
1826 Points
583 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 29, 2012 08:08 AM|LINK
This will insert your gridview row by row.
try
{
DataTable table = ViewState["CurrentTable"] as DataTable;
if (table != null)
{
foreach (DataRow row in table.Rows)
{
string DrpddSlabtype = row.ItemArray[1] as string;
string TextBoxLoadFrom = row.ItemArray[2] as string;
string TextBoxLoadTo = row.ItemArray[3] as string;
string TextBoxTimeFrom = row.ItemArray[4] as string;
string TextBoxTimeTo = row.ItemArray[5] as string;
string TextBoxLoadRate = row.ItemArray[6] as string;
//string TextBoxLoadAmount = row.ItemArray[7] as string;
if (DrpddSlabtype != null || TextBoxLoadFrom != null || TextBoxLoadTo != null || TextBoxLoadRate != null || TextBoxTimeFrom != null || TextBoxTimeTo != null)
{
string Insert_Ratesql = "INSERT INTO tblRateCard (Contract_Id, Service, Slab_Type, From_Visit, To_Visit, From_Time, To_Time, Rate, Created_By, Created_Date, Modify_By, Modify_Date,Uniqueid,Rate_Id)VALUES ('" + txt_Contractid.Text + "','Cash','" + DrpddSlabtype + "','" + TextBoxLoadFrom + "','" + TextBoxLoadTo + "','" + TextBoxTimeFrom + "','" + TextBoxTimeTo + "','" + TextBoxLoadRate + "','RAJ','" + DateTime.Now.ToString() + "','RAJ1','" + DateTime.Now.ToString() + "','" + strNextSeq + "','" + UFile + "')";
//string Insert_Ratesql = "INSERT INTO Cash_RateCard(Contract_Id,Cs_Type,Cs_From,Cs_To,Cs_Rate,Cs_Amount ,Created_By,Created_Date,Modify_By,Modify_Date,Cs_Id) VALUES ('" + txt_Contractid.Text + "','" + DrpddSlabtype + "','" + TextBoxLoadFrom + "','" + TextBoxLoadTo + "','" + TextBoxLoadRate + "','" + TextBoxLoadAmount + "','RAJ','" + DateTime.Now.ToString() + "','RAJ1','" + DateTime.Now.ToString() + "','" + UFile + "') ";
SqlCommand custCommand = new SqlCommand(Insert_Ratesql, dbConnection);
custCommand.ExecuteNonQuery();
dbConnection.Close();
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
Regards
Rima Gandhi.
Software Developer.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 29, 2012 08:36 AM|LINK
Hi,
Just please use SqlCommand with an Insert statement and then do inserting by using SqlParameter values and then do ExecuteNonQuery().
Reguards & Thanks
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 29, 2012 05:02 PM|LINK
what will be the sqlparameter ? here is the button click.
protected void Button2_Click(object sender, EventArgs e) { SqlConnection conn; SqlCommand cmd = new SqlCommand(); string strSQL = "Insert INTO penalties (DAY,P1,P2,OVER) Values (@DAY,@P1,@P2,@OVER)"; string bag_str = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString; conn = new SqlConnection(bag_str); conn.Open(); cmd.Connection = conn; cmd.CommandText = strSQL; cmd.Parameters.Add(new SqlParameter("@DAY", TextBox3.Text)); cmd.Parameters.Add(new SqlParameter("@P1", TextBox4.Text)); cmd.Parameters.Add(new SqlParameter("@P2", TextBox5.Text)); cmd.Parameters.Add(new SqlParameter("@OVER", TextBox6.Text)); int i = cmd.ExecuteNonQuery(); conn.Close(); if (i > 0) Response.Write("Succes."); else Response.Write("Error."); }waiting your answers
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 30, 2012 12:38 AM|LINK
Your SqlCommand's syntax seems right, and:
are Sql Parameters.
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 30, 2012 06:43 PM|LINK
Of course i know they are sql parameters.
But i told you. Look at my 1st entry on this page. I have 2 datetimepicker, 1 dropdownlist.
i will choose 2 dates, i will choose the employee and i will enter the values DAY, P1, P2, OVER. After clicking button, i need to insert data, according to this criterias.
Did you understand what i mean ?
Thanks.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 30, 2012 11:49 PM|LINK
Hi again,
So please first you should elebrate your question more clearly.
Then let's come to your question:
Just use your own values from these controls and then do batching:
protected void Button2_Click(object sender, EventArgs e) { SqlConnection conn; SqlCommand cmd = new SqlCommand(); string strSQL = "Insert INTO penalties (DAY,P1,P2,OVER) Values (@DAY,@P1,@P2,@OVER)"; string bag_str = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString; conn = new SqlConnection(bag_str); conn.Open(); cmd.Connection = conn; cmd.CommandText = strSQL; cmd.Parameters.Add(new SqlParameter("@DAY", TextBox3.Text)); cmd.Parameters.Add(new SqlParameter("@P1", Dropdownlist1.SelectedValue)); cmd.Parameters.Add(new SqlParameter("@P2", someControl.Property)); cmd.Parameters.Add(new SqlParameter("@OVER", someControl2.Property)); int i = cmd.ExecuteNonQuery(); conn.Close(); if (i > 0) Response.Write("Succes."); else Response.Write("Error."); } If there's anything, please be patient and feel free to continue, But please more clearly.Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Data According To Dropdownlist Criteria
Dec 31, 2012 12:24 PM|LINK
You do not give and answer really, just writing my code against me :)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Data According To Dropdownlist Criteria
Jan 01, 2013 12:20 AM|LINK
Sorry but please don't misunderstand, please kindly see my codes——
I've changed your SqlParameters' values——Look at this:I've used Dropdownlist's SelectedValue because as far as I see,It's you that wanna update values from Dropdownlist or other controls' values.
Thanks anyway!
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Data According To Dropdownlist Criteria
Jan 01, 2013 02:36 PM|LINK
Okay, sorry about that missunderstanding my friend, that's my bad :)
The answer is nearly found.Thanks for your answer. But here is the problem. This commands adds new rows into my table, i need to insert an existing row.
Here something to make your mind clear;
i have penalties table which includes that columuns ;
[ID],[NAME],[TYPE],[MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN],[TOTAL],[DAY],[P1],[P2],[OVER].
Includes ;
ID NAME TYPE MON TUE WED THU FRI SAT SUN TOTAL DAY P1 P2 OVER DATE
---------------------------------------------------------------------------------------------------------------------------------------------
1 mike out 250 350 100 0 0 200 0 900 - - - - 22-06-2012
2 john in 350 150 200 200 100 0 100 1100 - - - - 28-06-2012
As you see from here my friend, i will choose the dates from my datetimepickers, i will choose the employee from my dropdownlist and i will enter the values into textboxes and after that i will click finish button.
the day,p1,p2 and over values must be inserted into that chosen employee.
waiting your answer please, i need it too badly..
thanks.