Hello everyone.I am new to vb.net 2008 and i am in trouble.The problem for me is that i am making a windows form for a company and i am in a mess in getting my database connection to my datagridview by clicking a button and my data should been shown in datagridview.pls give me suggestion about datasets and connection strings.and even i want to print the document.so pls help me out.
Edited 4 Years Ago by harsh01ajmera: spelling errors
what database you are using then?
Connection String Sample :
in ButtonClick Event do this :
Try Using conn As New MySqlConnection("your string connection") conn.Open() Dim adapter As New MySqlDataAdapter("select * from table_name", conn) Dim dt As New DataTable adapter.Fill(dt) DataGridView1.DataSource = dt adapter.Dispose() conn.Close() End Using Catch ex As Exception MessageBox.Show(ex.Message) End Try
i use MySql for sample.
@artemix22 my database is an access file.See i am having two windows form i.e 1st is Login Page and 2nd is my Document Page.Now in my doucment page i have three buttons and a datagridview.now 1st button is (Browse),2nd is Print and 3rd is cancel.now main concern is that i cannot open or get my connection string using a dataset in datagridview.and one more thing...i don't want to open my database on form_load_events.so help me with this also.
Edited 4 Years Ago by harsh01ajmera
call this code on ur button click to display ur records in datagridview
'open connection Try Dim myCommand As New OleDbCommand With myCommand .CommandText = "SELECT * FROM tablename" .CommandType = CommandType.Text .Connection = Connection End With Dim dt As New DataTable dt.Load(myCommand.ExecuteReader) With DatagridView1 .AutoGenerateColumns = True .DataSource = dt End With Catch ex As Exception MsgBox("Error in select query: " + ex.Message) End Try 'close connection
well thank you @poojavb for helping me.i will try this code and let u know my reply.and one more thing,my database is opening directly on form_load events.so how can i stop that.
Instead of opening ur database in form load event try to open it in ur click events....
Did you salve the problem yet?
and i am in a mess in getting my database connection to my datagridview
What should that suppose to mean exaclty?
Do you have problems with connection string, or with getting data from database to dgv?
Mark thread as solved if its done....
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...
Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...
Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.
This is the result of previous question answered :
code for the listbox - datagridview interaction
At the top of the code ...