Click here to Skip to main content
15,916,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

need help on this

I have this code on Main form load event
C#
daVariables.SelectCommand = new SqlCommand("SELECT * from Variables", cs);
            dsVariables.Clear();
            daVariables.Fill(dsVariables);

            VariablesBS.DataSource = dsVariables.Tables[0];


txtmain.DataBindings.Clear();
            txtmain.DataBindings.Add(new Binding("Text", VariablesBS, "Main"));

            txtdata.DataBindings.Clear();
            txtdata.DataBindings.Add(new Binding("Text", VariablesBS, "Data"));

            txtdatadetails.DataBindings.Clear();
            txtdatadetails.DataBindings.Add(new Binding("Text", VariablesBS, "DataDetails"));

txtmain,txtdata and txtdatadetails are textboxes and this works ok, but I wont bind string instead of textboxes, because those textboxes are invisible, and I want to avoid even to have them, but string does not have databinding option,

how to do this

thank you
Posted
Updated 12-Aug-13 22:33pm
v3
Comments
shonezi 13-Aug-13 6:35am    
I tried this, but it's all empty

SqlCommand command = new SqlCommand("SELECT * from Variables WHERE ID = @ID", cs);
command.Parameters.Add("@ID", SqlDbType.Int);
command.Parameters["@ID"].Value = Main.pattern3.Text;

cs.Open();
command.ExecuteNonQuery();

command.Parameters.AddWithValue("@Main", main);
command.Parameters.AddWithValue("@Data", amenu);
command.Parameters.AddWithValue("@DataDetails", amenu1);
command.Parameters.AddWithValue("@DataActivities", amenu2);
command.Parameters.AddWithValue("@DataHistory", amenu3);
command.Parameters.AddWithValue("@Storage", bmenu);
command.Parameters.AddWithValue("@StorageDetails", bmenu1);
command.Parameters.AddWithValue("@StorageActivities", bmenu2);
command.Parameters.AddWithValue("@StorageHistory", bmenu3);


cs.Close();

main, amenu, amenu1, amnenu2, and so own are strings, but I get all empty values
virusstorm 13-Aug-13 15:45pm    
I just noticed that you reposted this but changed the content slightly. Please don't repost things as it is abuse of the forum policy. I don't think you understand how ADO.NET works. Please read up on accessing data from a database:
http://msdn.microsoft.com/en-us/library/e80y5yhx.aspx
shonezi 14-Aug-13 2:15am    
thank you, it was my mistake what I did, I was so totally lost I havent even noticed I was making new question instead should have continued on this one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900