Hi!
I would like to have a specific record found on dbGridView in my database from C#.net. I'm programing with VStudio 2008/2010. I'm a beginner in C#.
My preocupation is: how can I convert this VB.Net's code to C#.Net's code. This is the link http://www.vbdotnetheaven.com/uploadfile/rohatash/how-to-find-specific-record-from-database-table-in-VB-Net/
Please i'm counting on your help.
Thank you,
Israel.
Loading
Satyapriya NayakPosted Dec 2, 2011, 10:14 AM
Iam attaching the application you run it.
First add a App.xml file to you application.
Then store the emp.mdb in bin folder.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Search
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student where sname like '%" + textBox1.Text + "%'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
if (Convert.ToBoolean(oledbda.Fill(ds, ("student"))))
{
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "student";
MessageBox.Show("match found");
}
else
{
MessageBox.Show("match not found");
}
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer
Israel MfwambaPosted Dec 2, 2011, 5:02 PM
Hi Satyapriya!
You cannot beleive how many times did you help me in that way. To learn one more how can I find a specific record in C#. Many thanx Satyapriya!
Tell me one think. Which kind of print report tools I should use to create my report. Others developers say that they use xml to do their print report... others say they are using Crystal report... Please I need some orientation about that.
Thank you,
ISRAEL.
Israel MfwambaPosted Dec 2, 2011, 9:12 AM
Thanx.
In running time there's a message that says this: the connectionString property has not been initialized.
I did add the following codes. But still reject!
Private void Form1_Load(object sender, EventArgs e)
con = new System.Data.OleDb.OleDbConnection();
//ds1 = new DataSet();
this.ficha_InscrTableAdapter.Fill(this.schoolDataSet.student);
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=c:/School/student.mdb";
con.Open();
MessageBox.Show("Database open");
con.Close();
MessageBox.Show("Database close");
{
}
}
}
Satyapriya NayakPosted Dec 1, 2011, 11:21 PM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Search
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
OleDbDataAdapter oledbda;
DataSet ds;
string str;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from student where sname like '%" + textBox1.Text + "%'";
com = new OleDbCommand(str, con);
oledbda = new OleDbDataAdapter(com);
ds = new DataSet();
if (Convert.ToBoolean(oledbda.Fill(ds, ("student"))))
{
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "student";
MessageBox.Show("match found");
}
else
{
MessageBox.Show("match not found");
}
con.Close();
}
}
}
Thanks
If this post helps you mark it as answer