ASP.NET - Coding Error Pls findout
Asked By Rahul
10-Feb-12 07:56 AM

I have error in this coding kindly finout and tel me the correct codings:
my error is
Updated SuccessfullyUpdated SuccessfullyError:System.ArgumentException: Column 'cid' does not belong to table Table. at System.Data.DataRow.GetDataColumn(String columnName) at System.Data.DataRow.get_Item(String columnName) at creditadd.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in d:\tour\creditadd.aspx.cs:line 241
.style2
{
width: 18%;
height: 39px;
}
.style3
{
width: 1764px;
}
.style1
{
width: 226%;
height: 26px;
}
.ctl00_Menu1_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
.ctl00_Menu1_1 { text-decoration:none; }
.ctl00_Menu1_2 { background-color:#669900;height:35px;width:1256px; }
my codings:
cmd = new SqlCommand("select cid from creditadd where userid='" + txusrid.Text + "' and username='" + txusrname.Text + "'", con);
adap =
new SqlDataAdapter(cmd);
ds = new DataSet();
adap.Fill(ds);
for(int k=0;k<ds.Tables[0].Rows.Count;k++)
{
int c =int.Parse(ds.Tables[0].Rows[k]["cid"].ToString());
cmd =
new SqlCommand("select sum(credit) AS total from creditadd where cid<=cid and userid='" + txusrid.Text + "' and username='" + txusrname.Text + "'", con);
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
total =
float.Parse(dr[0].ToString());
float f = total + float.Parse(txcredit.Text);
dr.Close();
cmd =
new SqlCommand("update creditadd set credit='" + txcredit.Text + "',total='" + txtotal.Text + "' where cid ='" + lbid.Text + "'", con);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
Response.Write("<script>alert('Updated Successfully');</script>");
[)ia6l0 iii replied to Rahul
The error is in the line highlighted below. The error clearly indicates that a column with name "cid" is not found in the table. The table is nothing but the DataTable. And in your case ds.Tables[0] is the datatable.
for(int k=0;k<ds.Tables[0].Rows.Count;k++)
{
int c =int.Parse(ds.Tables[0].Rows[k]["cid"].ToString());
cmd = new SqlCommand("select sum(credit) AS total from creditadd where cid<=cid and userid='" + txusrid.Text + "' and username='" + txusrname.Text + "'", con);
....
}
Hope this helps.
Reena Jain replied to Rahul
Hi,
As I have checked error is here
for(int k=0;k<ds.Tables[0].Rows.Count;k++)
{
int c =int.Parse(ds.Tables[0].Rows[k]["cid"].ToString());
cmd =
new SqlCommand("select sum(credit) AS total from creditadd where cid<=cid and userid='" + txusrid.Text + "' and username='" + txusrname.Text + "'", con);
first declare the int c out side the for loop then use c in query like this
new SqlCommand("select sum(credit) AS total from creditadd where cid<=" + c +" and userid='" + txusrid.Text + "' and username='" + txusrname.Text + "'", con);
this will solve your problem for sure
kalpana aparnathi replied to Rahul

hi,
There are couple of things that may go wrong:
1. The DataTable that
the DataGrid is bound to may be updated from a thread other than the UI
thread. The fix for this situation is to update the DataTable from the
UI thread. To do that, you can use Control::Invoke or
Control::BeginInvoke. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassinvoketopic1.asp for how Control::Invoke works and http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclassinvoketopic1.asp for Control::BeginInvoke.
2.
your timer may refresh your DataGrid on a thread other than the UI
thread. The solution for this is to use System.Windows.Forms.Timer and
instantiate it on the UI thread.
3. Re-binding the data grid may overwrite the DataGrid::DataMember property. To fix that you need to re-bind w/ the table name:
dataGrid1.DataSource = null; //This is the line need to be added
dataGrid1.DataSource = ds;
string tablename = ds.Tables[0].TableName;
this.dataGrid1.SetDataBinding(ds, tablename);
Hope this helps.

Error Handling in a called function Hi Guys, A quick question for you. I have a Sub which calls a Function several times. Both the Sub & Function have error handling. The problem is, when there is an error in the called Function, the calling Sub Error Handler fires. How can I get the Function Error Handler to fire? Cheers Pete You can return a boolean from the Function to indicate whther it was successful. For example: Private Sub SendTrades() On Error GoTo Err_Handler 'do some stuff If EmailTrades(parameters) Then 'Do more stuff. . . . Else MsgBox "Problem Description Resume Err_Resume End Sub Public Function EmailTrades(ByVal parameters as blah) As Boolean On Error GoTo Err_Handler 'do some emailing stuff. If it fails here, the function will return false will help you. Hi Vickey, Thanks for the speedy reply. In the function where the error occurs, I don't want it to return a boolean and exit. There is other
will help you Hi I am getting the following message at the time of compilation Error 52 The install location for prerequisites has not been set to 'component vendor's web framework files in the Application folder of setup project ? But I am getting the following error messages when compiling the setup project Error 1 The install location for prerequisites has not been set to 'component vendor's web on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 2 The install location for prerequisites has not been set to 'component vendor's web on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 3 The install location for prerequisites has not been set to 'component vendor's web on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 4 The install location for prerequisites has not been set to 'component vendor's web on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 5 The install location for prerequisites has not been set to 'component vendor's web on disk. See Help for more information. H: \ SOURCES \ IMPEX SETUP \ IMPEXSETUP \ IMPEXSETUP.vdproj IMPEXSETUP Error 6 The install location for prerequisites has not been set to 'component vendor's web
Web config error message When I try to open up a dotnetnuke site I get this error message: Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. Parser Error Message: Unrecognized configuration section 'connectionStrings' Source Error: Line 15: < / sectionGroup> Line 16: < / configSections> Line 17: <connectionStrings> Line 18: <!- - Connection String for SQL disk but can neither access it or save data on it. I added it same error message: Configuration Error Description: An error occurred during the processing of a configuration file required
SqlConnection = new SqlConnection([Your Connections String]) dim ds as new DataSet dim daTable1 as new SqlDataAdapter dim daTable2 as new SqlDataAdapter dim daTable3 as new SqlDataAdapter dim daTable4 as new SqlDataAdapter daTable1.SelectCommand = "select * from table1 where . . ." daTable2.SelectCommand = "select * from table2 where . . ." daTable3.SelectCommand = "select attempting to recreate what you mentioned however, I cannot find any means of producing a SqlDataAdapter in VS2005. I appear to only have the option to create SqlDataSources. What hapened to post_date, author, comments, ct_number FROM Comments WHERE ct_number = ctpt.ct_number"; SqlConnection conn = new SqlConnection(strConn); SqlDataAdapter da = new SqlDataAdapter(strSql, conn); da.TableMappings.Add("Customers1", "Customers"); da.TableMappings.Add("Customers2", "CTPT"); da.TableMappings.Add Nested = true; customerRepeater.DataSource = ds.Tables["Customers"]; customerRepeater.DataBind(); } I seem to be getting an error indicating: The name 'ds' does not exist in the current context. Do you know why