-1

Please I have a project and on one form is the database search parameters where SELECT username, password etc from databasename where value1= '"+text.text+"' etc and I need to pass the results into other text boxes in another form, how can I do this

This is the search form design:

This is the search form design

This is the form where i what to display the result of search form:

This is the form where i what to display the result of search form

This is the code i used in form 1

con.Open();
cmd = new SqlCommand("SELECT  surname, firstname, Sex, phone, address, dob, nameofdoctor, doctorsreport, diagnosis, drugsprescribed  FROM dbo.patient WHERE cardnumber='" + textBox1.Text + "' and dateofadmission='" + dateTimePicker1.Text + "' and dateofdischarge='" + dateTimePicker1.Text + "'", con);
sda = new SqlDataAdapter(cmd);
cmd.ExecuteNonQuery();
DataTable ds = new DataTable();
sda.Fill(ds);
Records rec = new Records(value, value1, value2, value3, value4, value5, value6, value7, value8, value9);
rec.ShowDialog();
magicandre1981
  • 27,895
  • 5
  • 86
  • 127

1 Answers1

0

first of all, you probalby shouldnt construct your sql statement that way, its very prone to sql injections, try using Sql Parameters (https://www.dotnetperls.com/sqlparameter)

for the main part of your question, you need a reference to that form and a method wich allows to set the textbox, consider you have formA where the sql statement is executed and formB where the textbox textboxB resides (the one you want to set), you will need to implement a public setter for the textbox on formB like

        public void SetTextboxB(string txt)
    {
        textboxB.Text = txt;
    }

now you can call formB.SetTextboxB("your desired text")

if you´re unsure where to pass the forms reference you cann always use Application.OpenForms (https://msdn.microsoft.com/en-us/library/system.windows.forms.application.openforms.aspx) to find formB in formA

considering formB is already running

var b = (Application.OpenForms["formB"] as formB)
b.SetTextboxB("Desired Text");
subkonstrukt
  • 446
  • 2
  • 15