Showing posts with label walkthrough. Show all posts
Showing posts with label walkthrough. Show all posts
Thursday, November 23, 2017
Wednesday, November 22, 2017
Tuesday, March 15, 2016
Monday, March 7, 2016
Thursday, February 25, 2016
Saturday, December 12, 2015
Tuesday, October 21, 2014
Monday, October 20, 2014
Sunday, March 10, 2013
C# + SQL Example #1
* Gets max row count
* Inserts a new row (value number greater than max rows)
* Displays row values
[CODE]
string connString = "Server=localhost;Database=cshptest;Uid=root;"; // Select DB
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
// Command to count the rows
conn.Open();
command.CommandText = "SELECT COUNT(*) FROM csdat";
int rows = Convert.ToInt32(command.ExecuteScalar());
int newrows = rows + 1;
conn.Close();
// Insert a new data row, with the value greater than last index value (ex. 5 + 1 = 6)
command.CommandText = "Insert into csdat (id,dataT) values('" + newrows + "','" + newrows + "');";
conn.Open();
command.ExecuteNonQuery();
conn.Close();
MySqlDataReader reader;
// Read data in each row
for (int i = 0; i <= rows; i++)
{
string cnt = i.ToString();
conn.Open();
command.CommandText = "Select dataT from csdat where id=" + cnt; // Select column from table
reader = command.ExecuteReader();
while (reader.Read())
{
MessageBox.Show(reader["dataT"].ToString()); // extract data from column
}
conn.Close();
}
[/CODE]
* Inserts a new row (value number greater than max rows)
* Displays row values
[CODE]
string connString = "Server=localhost;Database=cshptest;Uid=root;"; // Select DB
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
// Command to count the rows
conn.Open();
command.CommandText = "SELECT COUNT(*) FROM csdat";
int rows = Convert.ToInt32(command.ExecuteScalar());
int newrows = rows + 1;
conn.Close();
// Insert a new data row, with the value greater than last index value (ex. 5 + 1 = 6)
command.CommandText = "Insert into csdat (id,dataT) values('" + newrows + "','" + newrows + "');";
conn.Open();
command.ExecuteNonQuery();
conn.Close();
MySqlDataReader reader;
// Read data in each row
for (int i = 0; i <= rows; i++)
{
string cnt = i.ToString();
conn.Open();
command.CommandText = "Select dataT from csdat where id=" + cnt; // Select column from table
reader = command.ExecuteReader();
while (reader.Read())
{
MessageBox.Show(reader["dataT"].ToString()); // extract data from column
}
conn.Close();
}
[/CODE]
Monday, June 4, 2012
C# Database Programming Start-up Guide. Free E-Book
Subscribe to:
Posts (Atom)
-
ඔබ නොකියා 93i දුරකථයක් පාවිච්චි කරනවා නම්, කලින් කලට එහි මතකයට අද්භූතජනක යමක් සිදුවන බව ඔබ අත්දැක තිබෙනු ඇති. කිසිම හේතුවකින් තොරව හිටි අඩි...