473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Update colum question

Hi, Mert

I want to update the "read_status" colum when reading data, this is my
way as below:

//
-----------------------------------------------------------------------------------------------------
string strConn = "server=" + server + ";database=" + database + ";uid="
+ uid + ";pwd=" + pwd;
SqlConnection sqlConn = null;
SqlConnection updateConn = null;

try {
sqlConn = new SqlConnection(strConn);
sqlConn.Open();
SqlCommand sqlCmd = sqlConn.CreateCommand();
sqlCmd.CommandTimeout = 10000000;
string sql = "Select id, name From member Where read_status = 0";
sqlCmd.CommandText = sql;
SqlDataReader dataReader = sqlCmd.ExecuteReader();

updateConn = new SqlConnection(strConn);
updateConn.Open();
SqlCommand updateCmd = updateConn.CreateCommand();
updateCmd.CommandTimeout = 10000000;

while(dataReader.Read()){
// id
long id = Convert.ToInt64(dataReader["id"]);
string name = dataReader["name"].ToString();

// update read status
// * the application will stop to here *
updateCmd.CommandText = "Update member Set read_status=1 Where id=" +
id;
updateCmd.ExecuteNonQuery();
}
}
catch(Exception exp) {
MessageBox.Show("Error:" + exp.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
} finally {
// close
if(sqlConn != null)
sqlConn.Close();
if(updateConn != null)
updateConn.Close();
}
//
-----------------------------------------------------------------------------------------------------

When running the "update read status" line, the app will be stopped.
What's the matter with my code? Thanks a lot.

Jun 5 '06 #1
0 1031

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ben-Nes Michael | last post by:
Hi All Does 7.4 support defferable updates on unique column ? example unique INT colum named u_test has the following values: 1, 2, 3, 4, 5 can i do update table set u_test = u_test + 1;
5
by: Janick Bernet | last post by:
The following Update fails with SQL0407N on Colum "Name", although the source-table t_Addresses_2005 is defined with NOT NULL on that column: UPDATE Addresses.t_Paddresses Old SET (Name,...
5
by: Sadun Sevingen | last post by:
hi i get dataset from'an webservice so i don't have an adaptor... dataset's structure is same as mine database table.... how can i update database table according to dataset...
0
by: Ash | last post by:
Hi, I'm using Vb.NET webform, connecting to sql server database on the local machine. I used datagrid propery builder to add the edit, update and cancel colum. On the code, i have: Private...
2
by: Manish | last post by:
Hey folks I am having a weird problem in ASP .Net. My page is in C#. I have a datagrid, which populates based on selection in drop down box on ASP page. This datagrid has template textbox colum in...
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
3
by: Manikandan | last post by:
Hi, I have table with three columns as below table name:exp No(int) name(char) refno(int) I have data as below No name refno 1 a 2 b 3 c
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.