TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Israel
705
1.3k
216.3k
Running a simple loop for displaying and saving once
Feb 11 2020 4:07 AM
Hi,
I have one table and two tools:
“TblCompany”
“txtAccountNumber”
“btnRun”
My table looks like this:
ID | Account | Name
1 5.6 Selling
2 3.5 Bying
3 1.4 Mobile
I wrote some codes that make a normal and simple filter. The target filter is one the column “Account”.
Then why I’am doing to resolv it? I put each ID number inside of my codes and copy/paste the same block of codes to filter the next ID number to make the operation. But there is a problem? This table is growing up every day and its becoming little bit havy when processing. Then how can I do to make a one way loop until the latest record of my table displaying one by one the next account’s number that will be saved later and so on.
Please see my codes:
string
connectionString =
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Flex\\Accounting.mdf;Integrated Security = True"
;
SqlConnection conn =
new
SqlConnection(connectionString);
conn.Open();
string
commandString =
"select top 1 * from tblTest1 where ID='"
+ txtID.Text +
"' order by ID DESC"
;
SqlCommand sqlCmd =
new
SqlCommand(commandString, conn);
SqlDataReader read = sqlCmd.ExecuteReader();
if
(read.HasRows)
{
while
(read.Read())
{
txtAccount.Text = read[
"Account"
].ToString();
txtName.Text = read[
"Name"
].ToString();
}
}
else
{
}
read.Close();
conn.Close();
conn =
new
SqlConnection
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Flex\\Accounting.mdf;Integrated Security = True"
;);
if
(conn.State != ConnectionState.Open)
conn.Open();
SqlCommand comm =
new
SqlCommand();
comm.Connection = conn;
SqlParameter account =
new
SqlParameter(
"@account"
, SqlDbType.Varchar);
SqlParameter name =
new
SqlParameter(
"@name"
, SqlDbType.Varchar);
comm.Parameters.Add(account);
comm.Parameters.Add(name);
account.Value = txtAccount.Text;
name.Value = txtName.Text;
comm.Connection = conn;
comm.CommandText =
"insert into tblTest2 ([account],[name])values(@account,@name)"
;
{
{
try
{
comm.ExecuteNonQuery();
}
finally
{
conn.Close();
}
Reply
Answers (
2
)
datatable retreiving first record of the database
SocketException: when connection through mysql