Я пытаюсь создать приложение для Windows Forms, которое позволяет пользователю получать данные из документа SQL Access и отображать их в форме по одному за раз.Мне понадобится кнопка, которая позволит им увидеть следующий набор элементов данных в строке таблицы SQL.Эта часть была бы легкой для меня, за исключением того, что я не знаю, как отделить мои элементы данных SQL от того, что находится в строке.Вот мой код.
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string myconnstr = "provider=Microsoft.ACE.OLEDB.12.0; data Source=ordertest.mdb"; // the msaccess connect string
string mysql = "select sku, description, quantityonhand, quantityonorder, warehouse from inventory;"; // my sql query
OleDbConnection dbconn;
dbconn = new OleDbConnection(myconnstr); // created connection object using connect string
dbconn.Open(); // my connection
OleDbCommand dbcmd = new OleDbCommand();
dbcmd.CommandText = mysql;
dbcmd.Connection = dbconn;
OleDbDataReader myreader = dbcmd.ExecuteReader(); // execute sql statement, put results in datareader
while (myreader.Read()) // this is where I get my rows and loop them until they're all processed, is it something I need to do with this?
{
richTextBox1.Text = richTextBox1.Text + myreader["sku"].ToString();
richTextBox2.Text = richTextBox2.Text + myreader["description"].ToString();
richTextBox3.Text = richTextBox3.Text + myreader["quantityonhand"].ToString();
richTextBox4.Text = richTextBox4.Text + myreader["quantityonorder"].ToString() + '\n';
richTextBox5.Text = richTextBox5.Text + myreader["warehouse"].ToString() + '\n';
} // end of while
dbconn.Close();
}
Если это поможет, мой номер, количество и порядок указываются в целочисленных значениях, а описание и склад - в виде строк.