June 14th, 2003, 10:04 AM
Thread with SqlDataAdapter not working, plz help
I tried fetching a part of data from the database and tried to update it using thread, it is not working as I expected.
The result I got in the browser is as follows:
The Main() thread calls this after starting the new InstanceCaller threads.
SQL 1 : SELECT temp_id, temp_senddate FROM temp_mails WHERE company_id = 1 AND temp_send = 'N'
It is not moving ahead and displaying(details which has to bee displayed):
RECORDCOUNT 1 : 3
sTempID : 1
sTempID : 2
sTempID : 3
End of function
Below is the snapshot of my code:
/* CODE STARTS HERE */
public class nThread1 : System.Web.UI.Page
public SqlConnection objConnection;
string strConn = "server=(local)\\netsdk;database=Test;Trusted_Connection=yes";
string sTempID = "";
string sSql = "";
string sSQLCommand = "";
int iCount = 0;
private void Page_Load(object sender, System.EventArgs e)
objConnection = new SqlConnection(strConn);
Thread InstanceCaller = new Thread(new ThreadStart(InstanceMethod));
Response.Write("The Main() thread calls this after starting the new InstanceCaller threads.<BR>");
InstanceCaller.Priority = ThreadPriority.Highest;
public void InstanceMethod()
Response.Write ("Inside InstanceMethod <BR>");
SqlDataAdapter objTempDA = new SqlDataAdapter();
sSql = "SELECT temp_id, temp_senddate FROM temp_mails ";
sSql += "WHERE company_id = 1 AND temp_send = 'N'";
Response.Write ("SQL 1 : " + sSql + "<BR>");
SqlDataAdapter objDA = new SqlDataAdapter(sSql, objConnection);
DataSet objDS = new DataSet();
objDA.Fill (objDS, "temp_mails");
DataTable objDT = objDS.Tables;
Response.Write ("RECORDCOUNT 1 : " + objDT.Rows.Count + "<BR>");
if (objDT.Rows.Count > 0)
foreach (DataRow objDR in objDT.Rows)
sTempID = objDR["temp_id"].ToString();
sSQLCommand = "UPDATE temp_mails set temp_send='Y' WHERE company_id=1 AND temp_id = '" + sTempID + "'";
objTempDA.UpdateCommand = new SqlCommand(sSQLCommand, objConnection);
Response.Write ("sTempID : " + sTempID + "<BR>");
Response.Write ("End of function<BR>");
/* CODE ENDS HERE */
Where I am doing wrong.
NOTE: I commented the thread part and just called the function InstanceMethod(), it worked fine.
Please help me.
July 28th, 2003, 04:12 PM
Another way to connect to SQLServer
You don't need all this work. Near the toolbox there is "Server" from wich you select the database and drag the tables over the form. Then bellow the "properties" you heve something like "generate datase". All that you have to do now is in the Load event for the Form(double clik on the form Text area) to write this code:
this.sqlconnection.ConnectionString = @" "//for not using the "\\"
//depends on the number of the tables
this.sqldataadapter1.Fill(this.myDataSet,"the name of the table");
this.sqldataadapter2.Fill(this.myDataSet,"the name of the table");
this.sqldataadapter3.Fill(this.myDataSet,"the name of the table");
this.sqldataadapter4.Fill(this.myDataSet,"the name of the table");
this.datagrid.DataSource = this.myDataSet;
//if you want to bind the tables directly you could do something
//this.datafrid.DataMember = "the name of the table"
If you are having trouble send an email and i'l send you a piece of code and a database of my one to play with.
I hope that what I've just said to be in your help.
July 28th, 2003, 09:41 PM
What's the point of participating in a forum if you ask people to talk to you through e-mails? that's not the spirit of forums....