1
Answer

load data in datagridview control

Ask a question
Dipa Ahuja

Dipa Ahuja

14y
4.3k
1
hello i want to load data in datagridview control :

20100121_154215.jpg


n when i click on show button:

code for dat is :
 
string con = "Server=.\\SQLEXPRESS;Database=db1.mdf;Trusted_Connection=True;";

 SqlDataAdapter da = new SqlDataAdapter();


private void btnshow_Click(object sender, EventArgs e)
{
            string q = "select * from items where cname= " + "'"      +comboBox1.SelectedValue.ToString() + "'";
           
            textBox1.Text = comboBox1.SelectedValue.ToString();

            da = new SqlDataAdapter(q, con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGrid1.DataSource = ds;

 }




bt i get error at runtime on the statement

da.Fill(ds);
Error:Error
Unable to copy file "D:\WindowsApplication2\WindowsApplication2\db1_log.ldf" 
to "bin\Debug\db1_log.ldf".
The process cannot access the file 'D:\WindowsApplication2\WindowsApplication2\db1_log.ldf' 
because it is being used by another process.	WindowsApplication2

N when i stop the program this error continue to occur while building.. 

but when i restart my computer this error gone..

whts the reason??


Answers (1)