I'm using ASP.NET forms to build some quite lengthy questionnaires. I'm creating each page using a FormView control with an attached SQL dataSource. The select query is easy enough- Visual Studio generates:
(select * from table)
but for the update query, Visual Studio gives me:
UPDATE table SET field1=,field2=... etc.
and I need:
UPDATE table SET field1=#field1,field2=#field2... etc.
At the moment, I'm copying each field name, pasting it after the = and adding an '#', but this gets really tedious.
Is there a way of automatically adding a parameter for each field?
OK, found the solution now.
Click 'configure DataSource' on the SmartTag
On the 'Configure the Select statement' page of the wizard, choose 'Specify tables from a table or view
Click the 'Advanced' button
Select 'Generate Delete, Insert and update Queries'
NB, for this to work, your select statement must contain the Primary key of the table.
Using Third party Tool SSMS tool for Autogenerated StoredProcedures in MSSQLServer
It's Generated Insert,Update,Select,Delete Query with Parameter Use in DB
Related
I work asp.net and use "aspnet_regsql" for manage user and role .. but i have a problem with work 'data source'.
in 'data source' only show views in database and all table hidden.
I want to know is how the table will be displayed in the list.
please see 2 image in comment.
all table and data source configuration
All tables in your database are asp.net created tables, they don't show up in the list of available tables, try adding your own table to the database and see if it shows up there.
I have my dbml classes generated in my asp .net project.
I have a table called recepies and a table called components.
List<recepy> prods = db.recepies.Where(p => p.EndProd_id == id).ToList();
This is the line I use to get my records from database. I get the records I want so this command works just fine.
Now I want to enter my properties. No problem to enter my properties, unless I want to use a property linked to another table.
In my 'recepies' table I'm using an Id from my components table. When I look into my dbml, the link is present.
normally I should be able to get the property by the line
recepy.components.Id
except the 'components' isn't present as property... What did I do wrong?
thanks in advance!
Kind regards
Found the answer myself..
Turns out that the table is in need of a primary key as well. wasn't the case in my table.
when i update the database with some new relationship between tables, is there a way to update the edmx file as well?
(when i click update model from database, seems nothing changes)
Open .edmx file in Visual Studio and then simply right click on "Update model from database" and then select any table you need from the Add tab.
If nothing else works you can simply select all the tables delete them and then do the procedure mentioned above.
Right click on the designer and select "Update model from database". Then use the "Refresh" tab to pull any additional information down.
I have a report embedded in an ASP.NET page. The ASP.NET page has some checkboxes that the user can select which datapoints they want to have show up in the report.
In the code behind file I am setting up part of the WHERE clause to be used in the query based on which checkboxes are checked.
I am putting this string into a report parameter and am not sure how to implement that parameter in the query. Simply placing the parameter in the query thinking the value of the string would come across does not work. I have the correct syntax in the string that is being passed into the report.
How do I properly use a Report Parameter to alter the WHERE Clause of the query?
I am using SQL Server 2005.
Base the report on a stored procedure that takes a BIT parameter for each of the checkbox values.
Build the dynamic SQL in the stored procedure and execute it.
I have an ASP.NET project and would like to create a page where my system admins can modify database table data (insert, update, and delete rows).
First, I have a drop down that is databound based on the tables in the database:
DdlTable.DataSource = from x in dc.Mapping.GetTables()
orderby x.TableName.Replace("dbo.", "")
select new {TableName = x.TableName.Replace("dbo.", "")};
DdlTable.DataTextField = "TableName";
DdlTable.DataValueField = "TableName";
DdlTable.DataBind();
DdlTable.Items.Insert(0, "Select a Table");
Next, I would like to have a gridview (or some other data object) that is bound to a table upon selection, and have the columns, insert, update, and delete functionality built dynamically. Can this be done without coding for each specific table?
Obviously, I can create x number of gridviews and datasources, but I would like it to be built dynamically for flexibility and minimal coding.
Essentially, I want to have a simple web-based SQL manager.
Try...
Create a seperate datasource for each table (in code or mark-up, doesn't matter).
Make sure the gridview doesn't have a datasource set when the page loads.
On some event (button click, selectedindexchanged of your dropdown, etc.), set the gridview's datasource to whichever datasource is selected in the dropdown, make sure autogenerate = true, and then databind().
In short - no - you change your tables, you have to change your CRUD - there's no magic bullet.
You can try something like CodeSmith. Or you can just write something yourself -- shouldn't be too difficult, should it? Query the InformationSchema view for your table's fields and you have all of the information you need to build a function in your code-behind to generate the CRUD statements.