updating dataset when adding a new field in database in c# - c#

I have made a database and created a table with five fields and used add new datasource and added a new dataset by using that. And I have made a form and inserted all fields by dragging them into the form and changed lots of the properties. Now I need to add a new field into the table in database. Do I have to create a new datasource and a new dataset and do everything from beginning or there is a way to update the datasource and dataset so that the new field automatically appears in them?
Any answer would be appreciated.

As you can read here you should right-click the TableAdapter in the Dataset Designer and click 'Configure' the TableAdapter Configuration Wizard opens where you can reconfigure the main query that defines the schema of your table. This should leave the additional TableAdapter queries (the additional methods) that were added after initial configuration.
So follow these steps
Open you xsd file.
Right click on Fill,GetData -> Configure
Click Query builder and add the new column in the query statment
Click ok and then your dataset is updated with the new database structure
If it doesn't work try deleting the dataTable and drag your table from Server Explorer again in your xsd file

Related

Extend View and Dataset of new column. Giv empty columns only new columns

I have problem with new columns in datagrid. I have many columns but I need to add 3 more.
In SQL Server 2008 Management Studio, I design the view and add more columns that exist in the ViewTable "V_FKD".
In VS2008 DataSet Designer. I add fine columns to DataSet table "V_FKDD" and in DataSet TableAdapter "V_FKDD_TableAdapter" extend all query.
The query works fine in Management Studio.
I add 3 new column to DataGridView to which it is assigned BindingSource to which it's is assigned DataSet.
And all columns in row have data but my new columns are always empty (I check this in DB I have many rows).
Please tell me why? How to resolve this problem?
Resolved! Program have other query (SqlCommand) in control BackgroundWorker

how to fill Dataset with custom built DataTable using c#?

I have to make a report.rdlc where i have to pass a dataset to it
I have DataTable made using C# not SQLDATAADAPTER other wise it can be filled as
adpt.fill(ds);
but i have only custom built DataTable using c# having columns and rows
How to make it datasource of report or make it dataset
Actually Simple... A Dataset is nothing but a collection of "DataTable" instances. You should be able to do via..
var DS = new DataSet();
YourCustomPopulatedDataTable.TableName = "SomeTable";
DS.Tables.Add( YourCustomPopulatedDataTable );
What * have done was created a baseline "ReportManager" class, but after I get the dataset with data back, I Write the XML output but also the XSD something like
DS.WriteXmlSchema( "MyXYZReport.xsd"); // the report will get this in a moment
DS.WriteXml( "MyXYZReport.xml");
Then, modify your project and add the ".xsd" file created so you don't have to fat-finger the schema for the report. So, the first time through, I query the data, generate the XSD/XML and stop before the actual report. Then, modify the project and add the XSD to it.
Now, open your rdlc. On the left-side you should have a panel for "Report Data". If not, click anywhere within your report, but not a specific object. Just enough to give focus you are working with the .RDLC. Then, click on "View" from the menu and the last item should show "Report Data" option. Once that is displayed, it will show how / where data comes from, parameters, images, data sources, data sets, etc.
Click on DataSets, right-click to Add Dataset and pick the .XSD you added to your project. This will display a dialog prompting with a "Name" to refer as in the report, then a data source. The Data Source should list the name such as "MyXYZReport". Under that will be "Available Datasets" and have the name of the tables within your dataset. Notice the one line change I did above to "name" the table before writing the XSD. Whatever that name is ("SomeTable" ), should be listed in the Available Datasets. Select that. Then, from my purpose, I change the "Name" of the dataset (the first field in the dialog) to the same value "SomeTable". This way, I am not guessing at which name is which. They will all refer to this as "SomeTable".
Now, in the report when you start adding controls, the expression dialog will show your "known" datasets (table instances) and associated fields to go.

Add new column to table in linqtosql dbml - The selected class cannot be deleted

I wish to add a new column to a table, usually I would add the column in SQL and then remove/add the table in the dbml to refresh its definition.
But if I try to delete the table I get
The selected class cannot be deleted because it is used as the return
type for one or more DataContext methods.
What is the best way to get around this to add a new column?
Thanks
You don't need to remove/add the table in dbml to refresh its definition. Just right click on your existing entity on dbml designer -> "Add Property".
(You can also do it on designer generated code file by adding new property)
When you updated table definition and trying to update DBML and getting this error,
Go in to yourproject.designer.vb, search for the "Table Name" , find related stored procedure and delete it. Then add table to DBML. Then add the related stored procedure again. That should solve your issue. Hope it will help

Using SQL Server Database View for populating DataGridView and modifying data in DB

Using SQL Server Database View for populating DataGridView and modifying data in DB
I want to know that how this will be done and if this is not a good solution, then please elaborate if any other good solution is possible.
1) Initially I want to use a Database View for populating different DataGridViews.
2) Multiple joins from multiple tables are required for the data-retrieval for each individual DataGridView.
3) The values from these DataGridViews are then populated in Controls (i.e. Textboxes/Combo-boxes) (For reference please see the images at this link: link text).
4) When the User changes the values in Controls, and clicks Save, the data earlier retrieved from DataGridView (via View) is to be updated in the Database.
NOTE:I am working on C-Sharp Windows Application and using SQL Server 2005.
1) I'm not sure how you can bind a control directly to a View, but you can edit your DataSet (assuming your using the designer under data sources right click on your dataset and click "edit dataset in designer", once there you can right click and add a table adapter which you can populate however you want (For example
SELECT * FROM [YourView]
Alternatively you could just use a stored procedure or type the SQL there to populate the Table Adapter.
Once you have added a table adapter to your dataset you can bind your DataGrid to that table adapter just as you would to a regular table.
I know this is probably now what your looking for but the truth is that I came across your question while looking for a way to do more or less the same thing.
2) You table adapter can be based on many tables using either a SQL statement or a Stored Procedure.
3) Why don't you directly bind those controls using their datasource property?
4) If the controls are themselves bound then you can change the data through the controls and to see the changes in your datagrid you should just need to "refresh" (call it's databind() method) to see the updated data.

Display SQL Server table in DataGridView

I think it's kind of noob question but I'm new to SQL Server in .NET and I've already lost several hours on this...
I started new project, inserted DataGridView on empty form and as Data Source I chose Add->Database and I created new SQL Server Database File. I called it db.mdf. Now I get DataSet named dbDataset and BindingSource named dbDataSetBindingSource. I also added LINQ to SQL Classes to my project and dragged my table (where I added some rows before) to my .dbml. Next I doubleclicked my dbDataset and in designer dragged and dropped the same table.
I hope you have an image now ;). The thing is that when I run program, nothing shows in DataGridView. I know that I can do
dbDataClassesDataContext db = new dbDataClassesDataContext();
var records= from rec in db.MyTable select rec;
dataGridView1.DataSource = records;
And it works perfect. But I believe that dbDataSet and dbDataSetBindingSource should work too... How to use them just to show data in DataGridView?
OMG, found it... For any others with this problem in future. Click on BindingSource in designer and in properties choose table in DataMember.

Categories

Resources