It is a windows application.
Originally I have a dataset for a dropdown menu from a table. Now I want to use a stored procedure. How to modify the process in the code?
I think that maybe the best way is to delete the the dataset and recreate a new dataset. But can we do in the designer code?
Thanks.
EDIT
protected Problem_DE_DataSet(global::System.Runtime.Serialization.SerializationInfo info, global::System.Runtime.Serialization.StreamingContext context) :
base(info, context, false) {
if ((this.IsBinarySerialized(info, context) == true)) {
this.InitVars(false);
global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler1 = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
this.Tables.CollectionChanged += schemaChangedHandler1;
this.Relations.CollectionChanged += schemaChangedHandler1;
return;
}
string strSchema = ((string)(info.GetValue("XmlSchema", typeof(string))));
if ((this.DetermineSchemaSerializationMode(info, context) == global::System.Data.SchemaSerializationMode.IncludeSchema)) {
global::System.Data.DataSet ds = new global::System.Data.DataSet();
ds.ReadXmlSchema(new global::System.Xml.XmlTextReader(new global::System.IO.StringReader(strSchema)));
if ((ds.Tables["Problem_DE"] != null)) {
base.Tables.Add(new Problem_DEDataTable(ds.Tables["Problem_DE"]));
}
this.DataSetName = ds.DataSetName;
this.Prefix = ds.Prefix;
this.Namespace = ds.Namespace;
this.Locale = ds.Locale;
this.CaseSensitive = ds.CaseSensitive;
this.EnforceConstraints = ds.EnforceConstraints;
this.Merge(ds, false, global::System.Data.MissingSchemaAction.Add);
this.InitVars();
}
else {
this.ReadXmlSchema(new global::System.Xml.XmlTextReader(new global::System.IO.StringReader(strSchema)));
}
this.GetSerializationData(info, context);
global::System.ComponentModel.CollectionChangeEventHandler schemaChangedHandler = new global::System.ComponentModel.CollectionChangeEventHandler(this.SchemaChanged);
base.Tables.CollectionChanged += schemaChangedHandler;
this.Relations.CollectionChanged += schemaChangedHandler;
}
Well the code is easy. Implying your SQLCommand is called myCommand
Change the
myCommand.Textto the name of the stored procedure.Change the
myCommand.CommandTypetoCommandType.StoredProcedure.For each parameters you have in you stored procedure use this line :
myCommand.Parameters.AddWithCalue("@YourSQLParameter",YourValue)I like using
DataReadersfor this type of operation.SQLDataReader myReader = myCommand.ExecuteReader();Voila ! You’re StoredProcedure is executed.
Now let’s say you want to add the results of the sotred procedure to the
ComboBox.while (myReader.Read()){
myComboBox.Items.Add(myReader["ColumnName"].Tostring();
}
Basic example but i’m sure you get the point. If you need more info you can always read this tutorial it pretty much explain what you want.
Update :
It got messy with the generated code you posted up there but the approach is still the same. From what I understand you only want to read from a table using a Stored Procedure and fill a ComboBox or DropDownList with a certain field. You should try and type it from scratch in the code section without using this designer to understand how it works.
You should have something like this :