update database
-
hii m trying to update the column ProductID of table Product.db i have written the following code on pageload but its giving error: syntax error in update statement.where m i wrong.plz guide. the code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String str2 = "Select PID From Product Where(ProductID='PID1')";
OleDbCommand cmd = new OleDbCommand(str2, conn);
conn.Open();
string m = cmd.ExecuteScalar().ToString();
m = "PID" + m;
conn.Close();
string str3 = "Update Product Set(ProductID='" + m + "')Where(ProductID='PID1')";
cmd = new OleDbCommand(str3, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
populateddl1();
populateddl2();
}
} -
hii m trying to update the column ProductID of table Product.db i have written the following code on pageload but its giving error: syntax error in update statement.where m i wrong.plz guide. the code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String str2 = "Select PID From Product Where(ProductID='PID1')";
OleDbCommand cmd = new OleDbCommand(str2, conn);
conn.Open();
string m = cmd.ExecuteScalar().ToString();
m = "PID" + m;
conn.Close();
string str3 = "Update Product Set(ProductID='" + m + "')Where(ProductID='PID1')";
cmd = new OleDbCommand(str3, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
populateddl1();
populateddl2();
}
}Well, the brackets in your SQL are at a mininum, superfluous. Why would you change all product IDs from a known value to the new one ? This code is an utter disaster, but I think it should work. However, I don't think this is what's blowing up. Are you sure this is the issue, because ASP.NET will only identify an 'update statement', if you try to use one of it's nasty, SQL holding controls that tries to update things for you. I think you've got the code there to use an updating control, and not the code in that control to do the update as it expects.
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.
-
Well, the brackets in your SQL are at a mininum, superfluous. Why would you change all product IDs from a known value to the new one ? This code is an utter disaster, but I think it should work. However, I don't think this is what's blowing up. Are you sure this is the issue, because ASP.NET will only identify an 'update statement', if you try to use one of it's nasty, SQL holding controls that tries to update things for you. I think you've got the code there to use an updating control, and not the code in that control to do the update as it expects.
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.
Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:
string str1 = "Select MAX(PID) From Product";
OleDbCommand cmd = new OleDbCommand(str1, conn);
conn.Open();
string max= cmd.ExecuteScalar().ToString();
if (max == "")
{
max = "PID" + 1;
}
else
{
int i= Convert.ToInt32(max) + 1;
string s1=Convert.ToString(i);
max = "PID" + s1;
}
conn.Close();
string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
cmd = new OleDbCommand(str, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
str = "Select * From Product";
cmd = new OleDbCommand(str, conn);
OleDbDataReader dr1 = null;
conn.Open();
dr1 = cmd.ExecuteReader();
DropDownList2.DataSource = dr1;
DropDownList2.DataTextField = "ProductID";
DropDownList2.DataValueField = "ProductID";
DropDownList2.DataBind();
conn.Close();so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.
-
Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:
string str1 = "Select MAX(PID) From Product";
OleDbCommand cmd = new OleDbCommand(str1, conn);
conn.Open();
string max= cmd.ExecuteScalar().ToString();
if (max == "")
{
max = "PID" + 1;
}
else
{
int i= Convert.ToInt32(max) + 1;
string s1=Convert.ToString(i);
max = "PID" + s1;
}
conn.Close();
string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
cmd = new OleDbCommand(str, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
str = "Select * From Product";
cmd = new OleDbCommand(str, conn);
OleDbDataReader dr1 = null;
conn.Open();
dr1 = cmd.ExecuteReader();
DropDownList2.DataSource = dr1;
DropDownList2.DataTextField = "ProductID";
DropDownList2.DataValueField = "ProductID";
DropDownList2.DataBind();
conn.Close();so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.
Why you are repeating the post?? This should be your answer http://www.codeproject.com/Messages/3179523/access.aspx
Coding C# ExciteTemplate
-
Why you are repeating the post?? This should be your answer http://www.codeproject.com/Messages/3179523/access.aspx
Coding C# ExciteTemplate
-
Actually i want to insert data in Product.db table it has columns named: PID: which is auto number ProductID:Which is Primary key and others columnss are:ProductName,ProductDescription,ProductPrice,VendorID; i want the entries in ProductID table like when PID value is 1 ProductID value becomes PID1.in have written code for this on button click.but the Promblem occurs that when somebody deletes the rows of the table the new PID Value doesnt start from 1.it start from last deleted value of PID.Now i want that ProductID value gets update according to the PID value.the code at button click is:
string str1 = "Select MAX(PID) From Product";
OleDbCommand cmd = new OleDbCommand(str1, conn);
conn.Open();
string max= cmd.ExecuteScalar().ToString();
if (max == "")
{
max = "PID" + 1;
}
else
{
int i= Convert.ToInt32(max) + 1;
string s1=Convert.ToString(i);
max = "PID" + s1;
}
conn.Close();
string str = "Insert Into Product(ProductID,ProductName,ProductDescription,ProductPrice)Values('"+max+"','" + txtprdtname.Text + "','" + txtprdtdescrp.Text + "','" + txtprdtprice.Text + "')";
cmd = new OleDbCommand(str, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
str = "Select * From Product";
cmd = new OleDbCommand(str, conn);
OleDbDataReader dr1 = null;
conn.Open();
dr1 = cmd.ExecuteReader();
DropDownList2.DataSource = dr1;
DropDownList2.DataTextField = "ProductID";
DropDownList2.DataValueField = "ProductID";
DropDownList2.DataBind();
conn.Close();so m trying to update the ProductID value AS i have default inserted PID1 when the first row is inserted in Product table.
Well, this code is excrable. Why would you assume that any postback is a new row ? Why would you not do all your code for an insertion inside your event ? Why would you not have a data layer ? Everything about this code is terrible. You should buy a book on ASP.NET and one on ADO.NET, and read them before writing any code. I assume no-one is paying for this code, if they are, you are a liar and a thief.
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.
-
m not insertin PID in Product table but m inserting ProductID value and it is necessary as it is primary key and cannot be null.
If it's the primary key, why not make it an identity ? Either way, why not write a data layer, or at least write code to a semi professional standard ?
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.
-
Well, this code is excrable. Why would you assume that any postback is a new row ? Why would you not do all your code for an insertion inside your event ? Why would you not have a data layer ? Everything about this code is terrible. You should buy a book on ASP.NET and one on ADO.NET, and read them before writing any code. I assume no-one is paying for this code, if they are, you are a liar and a thief.
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.
Christian Graus wrote:
I assume no-one is paying for this code, if they are, you are a liar and a thief.
Depends on how much they pay for it Christian ;>
var question = (_2b || !(_2b));
-
Christian Graus wrote:
I assume no-one is paying for this code, if they are, you are a liar and a thief.
Depends on how much they pay for it Christian ;>
var question = (_2b || !(_2b));
Well, I am sure they know their website would cost $12000 to write in the US, and believe that the $50 they are paying this guy will get the same result. They probably deserve each other.
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.