query
-
hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:
protected void Button2_Click(object sender, EventArgs e)
{
OleDbDataReader dr = null;
string str = "Select Count(Specification)From ProductSpecification";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
string Count = cmd.ExecuteScalar().ToString();
int count = Convert.ToInt32(Count);
conn.Close();
str = "Select * From ProductSpecification";
cmd = new OleDbCommand(str, conn);
conn.Open();
// dr = cmd.ExecuteReader();
//DataTable dt = new DataTable();
// dt.Load(dr);for (int i = 1; i <= count; i++) { txt = new TextBox\[count\]; //string s=dr\["Specification"\].ToString(); //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID); ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString()); txt\[i\] = new TextBox(); txt\[i\].ID = "txt" + i.ToString(); string s1 = txt\[i\].Text; string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')"; cmd = new OleDbCommand(s2, conn); cmd.ExecuteNonQuery(); } conn.Close(); }
but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.
-
hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:
protected void Button2_Click(object sender, EventArgs e)
{
OleDbDataReader dr = null;
string str = "Select Count(Specification)From ProductSpecification";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
string Count = cmd.ExecuteScalar().ToString();
int count = Convert.ToInt32(Count);
conn.Close();
str = "Select * From ProductSpecification";
cmd = new OleDbCommand(str, conn);
conn.Open();
// dr = cmd.ExecuteReader();
//DataTable dt = new DataTable();
// dt.Load(dr);for (int i = 1; i <= count; i++) { txt = new TextBox\[count\]; //string s=dr\["Specification"\].ToString(); //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID); ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString()); txt\[i\] = new TextBox(); txt\[i\].ID = "txt" + i.ToString(); string s1 = txt\[i\].Text; string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')"; cmd = new OleDbCommand(s2, conn); cmd.ExecuteNonQuery(); } conn.Close(); }
but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.
mylogics wrote:
txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;
Use this
txt = new TextBox();
txt= Page.FindControl("txt" & i.ToString);
string s1= txt.TextBe an Eagle, Sky is Yours.
-
mylogics wrote:
txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;
Use this
txt = new TextBox();
txt= Page.FindControl("txt" & i.ToString);
string s1= txt.TextBe an Eagle, Sky is Yours.
hiii now i have changed my code to:
protected void Button2_Click(object sender, EventArgs e)
{
OleDbDataReader dr = null;
string str = "Select Count(Specification)From ProductSpecification";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
string Count = cmd.ExecuteScalar().ToString();
int count = Convert.ToInt32(Count);
conn.Close();for (int i = 0; i <= Convert.ToInt32(Count) - 1; i++) { TextBox txtCtrl = (TextBox)Panel2.FindControl("txt" + (i + 1)); Label lblctrl = (Label)Panel2.FindControl("lbl" + (i + 1)); if (txtCtrl != null) { string s = txtCtrl.Text; string s2 = lblctrl.Text; string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'"; cmd = new OleDbCommand(s1, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); //TextBox1.Text = TextBox1.Text + "," + txtCtrl.Text; } } }
but it is givin error: Syntax error in UPDATE statement. plz help...
-
mylogics wrote:
txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text;
Use this
txt = new TextBox();
txt= Page.FindControl("txt" & i.ToString);
string s1= txt.TextBe an Eagle, Sky is Yours.
-
hiii now i have changed my code to:
protected void Button2_Click(object sender, EventArgs e)
{
OleDbDataReader dr = null;
string str = "Select Count(Specification)From ProductSpecification";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
string Count = cmd.ExecuteScalar().ToString();
int count = Convert.ToInt32(Count);
conn.Close();for (int i = 0; i <= Convert.ToInt32(Count) - 1; i++) { TextBox txtCtrl = (TextBox)Panel2.FindControl("txt" + (i + 1)); Label lblctrl = (Label)Panel2.FindControl("lbl" + (i + 1)); if (txtCtrl != null) { string s = txtCtrl.Text; string s2 = lblctrl.Text; string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'"; cmd = new OleDbCommand(s1, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); //TextBox1.Text = TextBox1.Text + "," + txtCtrl.Text; } } }
but it is givin error: Syntax error in UPDATE statement. plz help...
mylogics wrote:
string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";
Dear Friend Please write you query with space between where cluase and single quote
string s1 = "Update ProductSpecification Set Value='"+s+"' Where Specification='"+s2+"'";
Be an Eagle, Sky is Yours.
-
Hi sir i want to say my code is for text but i want 2 ask u how we use this code for date format.
Plz explain. put you code here...
Be an Eagle, Sky is Yours.
-
mylogics wrote:
string s1 = "Update ProductSpecification Set Value='"+s+"'Where Specification='"+s2+"'";
Dear Friend Please write you query with space between where cluase and single quote
string s1 = "Update ProductSpecification Set Value='"+s+"' Where Specification='"+s2+"'";
Be an Eagle, Sky is Yours.
-
If you passing text with single qoute like D'Souza then replace single quoute with ''.
Be an Eagle, Sky is Yours.
-
hiii m tryin to submit the values of dynamically created textbox on button click.i have writen following code on button click:
protected void Button2_Click(object sender, EventArgs e)
{
OleDbDataReader dr = null;
string str = "Select Count(Specification)From ProductSpecification";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
string Count = cmd.ExecuteScalar().ToString();
int count = Convert.ToInt32(Count);
conn.Close();
str = "Select * From ProductSpecification";
cmd = new OleDbCommand(str, conn);
conn.Open();
// dr = cmd.ExecuteReader();
//DataTable dt = new DataTable();
// dt.Load(dr);for (int i = 1; i <= count; i++) { txt = new TextBox\[count\]; //string s=dr\["Specification"\].ToString(); //TextBox text = (TextBox)Panel2.FindControl(txt\[i\].ID); ///TextBox txtctrl = (TextBox)Panel2.FindControl("txt" + i.ToString()); txt\[i\] = new TextBox(); txt\[i\].ID = "txt" + i.ToString(); string s1 = txt\[i\].Text; string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')"; cmd = new OleDbCommand(s2, conn); cmd.ExecuteNonQuery(); } conn.Close(); }
but it is givin error and also it is not taking the value of textbox: error:Syntax error in INSERT INTO statement.
Well, this has to be the most ridiculous code I've seen in a long time.
mylogics wrote:
txt[i] = new TextBox(); txt[i].ID = "txt" + i.ToString(); string s1 = txt[i].Text; string s2 = "Insert Into ProductSpecification(Value)Values('"+s1+"')";
Well, why would you expect s1 to be anything, but an empty string ? What on earth are you expecting here ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Hi sir i want to say my code is for text but i want 2 ask u how we use this code for date format.
your code is a disaster from start to finish. It has zero chance of working. You should rethink it, and perhaps do some study, so you have a basic idea of what you are doing. you should also read up on paramaterised queries, once your code is not totally useless, it will become totally insecure, due to SQL injection attacks. Once you fix that, it will also work for dates, as a side benefit.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.