It happens that I want to link the values that I put in the textbox of a form2 to a form1 that contains a Datagridview
It happens that I want to link the values that I put in the textbox of a form2 to a form1 that contains a Datagridview
You are missing information for your question, but if you need to access form 1 from 2, you must:
Form1 form_Principal = new Form1();
((TextBox)form_Principal.Controls["TextBox1"]).Text = "Texto";
And to fill your datagrid:
DataTable dt = new DataTable();
MySqlCommand comando = new MySqlCommand("select * from tabla where id='"+textBox11.Text+"'", conexion);
MySqlDataAdapter sda = new MySqlDataAdapter(comando);
sda.Fill(dt);
dataGridView1.DataSource = dt;
This code can adapt it to your needs
You must place for each column of your datagrig and the field of your table.
Greetings ..
Try Dim ivNumerCredito = DataGridView1.Rows(e.RowIndex).Cells(1).Value() Dim oConn As SqlConnection oConn = New SqlConnection("Server=192.168.105.150\SQL2012; database=DBProAuxQP; user id=sa; password=DBServ@14;") If oConn.State = 1 Then oConn.Close() oConn.Open() Dim table As New DataTable Dim Adp As New SqlDataAdapter() Adp.SelectCommand = New SqlCommand() ' Creando una Instancia de SqlCommand Adp.SelectCommand.Connection = oConn 'Conexión Adp.SelectCommand.CommandText = "PE_Cre_Consulta_Cargo" Adp.SelectCommand.CommandTimeout = 90000000 Adp.SelectCommand.CommandType = CommandType.StoredProcedure Adp.SelectCommand.Parameters.Add("@opt", SqlDbType.Int, 4) Adp.SelectCommand.Parameters("@opt").Value = 3 Adp.SelectCommand.Parameters.Add("@NomServer", SqlDbType.VarChar, 50) Adp.SelectCommand.Parameters("@NomServer").Value = CboServidor.Text Adp.SelectCommand.Parameters.Add("@FechaCarga", SqlDbType.Date) Adp.SelectCommand.Parameters("@FechaCarga").Value = "2013-11-25" Adp.SelectCommand.Parameters.Add("@Buscar", SqlDbType.VarChar, 15) Adp.SelectCommand.Parameters("@Buscar").Value = ivNumerCredito Adp.SelectCommand.Parameters.Add("@NCuota", SqlDbType.Int) Adp.SelectCommand.Parameters("@NCuota").Value = 0 Adp.Fill(table) Me.Close() Dim frm As New Form3 frm.Show() frm.TxtNroCredito.Text = ivNumerCredito frm.TxtCliente.Text = table.Rows(0)("Nombres") If table.Rows.Count > 0 Then frm.DtgCargos.Visible = True frm.DtgCargos.Rows.Clear() For Each Frow As DataRow In table.Rows frm.DtgCargos.Rows.Add(Frow.Item("IdcuotaCredito"), Frow.Item("Numero"), Frow.Item("FVto"), Frow.Item("Otros"), Frow.Item("Estado")) Next End If table.Dispose() Catch ex As Exception MsgBox(Err.Description, MsgBoxStyle.Critical, "..:: Aviso del Sistema ::..") Exit Try End Try End Sub