Jelmer Posted March 13, 2006 Posted March 13, 2006 Hello ' On a form i've got these components: datagridview dataset bindingsource FillbyToolstrip i've configured all things and it works. But i like to add a button to the form, and if i press it that there is executed another query. So... is it possible to change the FillByToolstrip with a code? so i can use another SQL Query ? thanx, Jelmer Quote
teixeira Posted March 17, 2006 Posted March 17, 2006 Hi, I'm guessing you're using the wizards to make that but, programmatically you can create a new DataSet and a new Command and a new DataAdapter; you specify your sqlquery associate it wit hthe command, fill the dataset with that command, and just bind the dataset to your existing bindingsource as: BindingSource myBindingSource = new BindingSource(); myBindingSource.DataMember = "TableName"; myBindingSource.DataSource = myDataSet.Tables["TableName"]; myBindingSource.ResetBindings(); And it should work fine .eof Teixeira Quote
Guest Fhwoarang Posted October 7, 2008 Posted October 7, 2008 Hi, I'm guessing you're using the wizards to make that but, programmatically you can create a new DataSet and a new Command and a new DataAdapter Is that the best way to do it? Creating multiple datasets and dataAdapters doesn't sound good to me (but I'm not an expert :) ). What I want to do is just set my SQL query and then make the bindingsource navigate only throught the query result, not the whole table. (since I'm using WHERE statements). I'm using wizard to bind it to TextBoxes and DataGridViews. The Fillby gives me the option to select a query, and it's in its command text property, but I want to change the given some values, not in a wizard. But when you bind a textbox, you don't use a Fillby (I think). Your response didn't completely answer my question. I would like to ask you to elaborate it a little more (just a little bit). I'm new to .NET and SQL Server and this ADO.NET thing. :) Maybe if you could start your response once somebody used the wizards to create the bindingSource (or maybe how to make a BindingSource without using the wizards at all; I don't know what's the best way). If anybody else could give me some insight, I will appreciate it too.:D Thanks. Quote
Guest Fhwoarang Posted October 12, 2008 Posted October 12, 2008 I have found the answer to my own question. I got a VERY useful example doing exactly what I wanted to do. Except that it doesn't use the BindingSource, but that's OK. https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6149&lngWId=10 The code is SUPER easy to understand. It has helped me a lot, and its approach is very similar to what I wanted to do. I really want to send an email to that guy I have one problem here. Take a look at this query. cmd.CommandText = "Delete from PersonInfo where (FullName = N'" & txtFullName.Text & "')" After FullName, there is an N. I don't know what is it for, or what does it do. The only weird thing the programm does is that it adds a number to a combobox, everytime you try to add a new record, but it keeps a count somewhere outside the .NET application (since I couldn't find a declaration for N or a counter inside the code). Maybe it is in the database. For instance, let's say it has 10 records and then I add a new one. Then a 11 appears at the combobox. If I delete the 11 record and try to ad a new one, an 12 appears, instead an 11, despite the fact the 11 no longer exists. What is happening here or how is he doing it? Quote
Administrators PlausiblyDamp Posted October 12, 2008 Administrators Posted October 12, 2008 The N specifies the string that follows in single quotes is a unicode string rather than an ansi string. It sounds like the table in the data base has an Identity column - basically it just increments for every record inserted. The only other thing I would say is thet the example you posted is open to a potential security risk and you would be much better off using a parameterised query rather than relying on string concatenation. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Guest Fhwoarang Posted October 12, 2008 Posted October 12, 2008 The only other thing I would say is thet the example you posted is open to a potential security risk and you would be much better off using a parameterised query rather than relying on string concatenation. Really? :eek: What are those risks? And what's a parameterised query? :p BTW, I'm not using ASP, this is a desktop application. :cool: Quote
Administrators PlausiblyDamp Posted October 13, 2008 Administrators Posted October 13, 2008 http://www.xtremedotnettalk.com/showthread.php?p=463520#post463520 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Guest Fhwoarang Posted October 13, 2008 Posted October 13, 2008 http://www.xtremedotnettalk.com/showthread.php?p=463520#post463520 There are no performable human actions to thank you enough for your answers. :) Quote
Guest Fhwoarang Posted October 14, 2008 Posted October 14, 2008 Edit: Nevermind, I solved my problem. :) BTW, just a question. I had to add Parameters.Clear() method after calling it for the first time, because on the second time, an error pop ups saying that you can't declare variables twice. Is this normal? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.