MS Access to sql server searching

Posted by malou17 on Stack Overflow See other posts from Stack Overflow or by malou17
Published on 2010-02-11T04:47:32Z Indexed on 2010/03/22 8:41 UTC
Read the original article Hit count: 308

Filed under:
|

How to use this code if we are going to use sql server database becaUSE in this code we used MS Access as the database

private void btnSearch_Click(object sender, System.EventArgs e) {
  String pcode = txtPcode.Text;
  int ctr = productsDS1.Tables[0].Rows.Count;
  int x;
  bool found = false;

  for (x = 0; x<ctr; x++) {
    if (productsDS1.Tables[0].Rows[x][0].ToString() == pcode) {
      found = true;
      break;
    }
  }

  if (found == true) {
    txtPcode.Text = productsDS1.Tables[0].Rows[x][0].ToString();
    txtDesc.Text = productsDS1.Tables[0].Rows[x][1].ToString();
    txtPrice.Text = productsDS1.Tables[0].Rows[x][2].ToString();
  } else {
    MessageBox.Show("Record Not Found");
  }

  private void btnNew_Click(object sender, System.EventArgs e) {
    int cnt = productsDS1.Tables[0].Rows.Count;
    string lastrec = productsDS1.Tables[0].Rows[cnt][0].ToString();
    int newpcode = int.Parse(lastrec) + 1;

    txtPcode.Text = newpcode.ToString();
    txtDesc.Clear();
    txtPrice.Clear();
    txtDesc.Focus();

here's the connectionstring

Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=0;Data Source="J:\2009-2010\1st sem\VC#\Sample\WindowsApplication_Products\PointOfSales.mdb"

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server