I am trying to create a page in C# for editing data in SQL Server, and the data is like title, date, description and that's not a big deal
The problem is each row of this has a foreign key to another table that has image URL so each row has like 3 OR more images.
Like I said before I want to create a page which can edit all of these, I made it with listview but it really really bad so I was trying to find another ideas so can you help me in that
Well, the foreign key isn't that difficult to deal with. When a user edits that FK, before you allow the change to be committed to the cell or saved, run a check against the Db to see if their entry is valid. If it is, allow the edit, if not, cancel their edit of that value.
If that other table is the only table that has a FK to worry about, you could return just the Ids in your initial call and check against the dataset to save some round trips.
Related
I am currently trying to create a project in ASP.NET to create a stock input web application for a cafe which allows users to input stock data from web. I want to know how to save data from browser to SQL Server.
Screenshot of my current table design / ERD
The Item table will hold all information about each item. Stock_Take_Item table will hold the quantity of each item for a stock take, and Stock_Take table will hold the date of the stock take.
I want to be able to present the user with three columns, One for item description (which will already contain the item descriptions in), the second column for Bar Quantity and able the user to input this value and the third Column for Storage Quantity and also allow the user to input this value.
Once a user has filled out the columns for the stock take, will then press a submit button which will trigger c# code to insert these values into the SQL Database.
I hope this isn't too long winded and someone can give me a good recommendation on how to do so. I fully understand my tables may be wrong, and am open to changing them.
This is not actually a question of the specific problem. you rather need to read a very basic tutorial of ASP.net application.
For your convenience, I suggest you to read This Basic Example which exactly does what you need and just the table name and field names differ. I suggest you read this up first and then come here for very specific questions.
This article here describes handling concurrency exceptions. The steps to reproduce the problem are:
Create a new Windows Application project.
Create a new dataset based on the Northwind Customers table.
Create a form with a DataGridView to display the data.
Fill a dataset with data from the Customers table in the Northwind database.
After filling the dataset, use the Visual Database Tools in Visual Studio to directly access the Customers data table and change a record.
Then on the form, change the same record to a different value, update the dataset, and attempt to write the changes to the database, which results in a concurrency error being raised.
Catch the error, then display the different versions of the record, allowing the user to determine whether to continue and update the database, or to cancel the update.
My question is, why does this even happen? Why can't I just save and edit the record from the DataGridView without causing any errors? I'm creating an app with a DataGridView and I'm facing this problem. I need some way to avoid or resolve this error without notifying the user, so whatever they see in the DataGridView gets saved exactly the way thy see it. What's the cause of that error?
The solution turned out to be pretty simple.
All you need to do is reload the data into the DataGridView again after every save.
So the code for the BindingNavigator save button is now:
this.Validate();
this.maintableBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.yourDataSet);
this.maintableTableAdapter.Fill(this.yourDataSet.yourtable);
I have no idea why this works, so I need an expert to confirm this. Working solution though.
Thanks to E-Bat for planting this idea in my head.
Inside microsoft sql server database I have table User with column Password. Password is of type varchar(50) and I want to change to varchar(255).
I tried using microsoft sql server management studio and using design view I tried manually to change 50 to 255 but on saving that action I'm getting alert
Following tables will be saved to your database. Do you want to continue?
User
xx
xx
xx
On chosing yes I'm waiting for whole min with mouse cursor busy and I'm getting back
Errors were encountered during the save process. Some database objects were not saved.
User table, Unable to delete relationship FK.....
Timeout expired.
I'm confused since I'm not changing anything but this lenght of Password column.
Is there any simple way to complete this simple operation, change varchar(50) to varchar(255)
When you use the designer to make changes, behind the scenes SSMS generates a huge script that creates a new temporary table, dumps all the data from the old one into the temporary one, deletes the old table and then renames the temporary table back to the name of the original name. It also is smart enough to drop foreign keys, constraints, etc. and then tries to put them all back later. Depending on the complexity of the table the script can be hundreds or thousands of lines long.
Instead, since you're really just asking for a little more space in your column which is keeping the same underlying data type, you could directly alter the data type of the column with a simple two-liner:
ALTER TABLE [dbo].[User]
ALTER COLUMN [Password] varchar(255) NOT NULL
GO
(Adjust the script according to whether the column is nullable, has defaults, etc.)
Of course you should have a backup of the database that table is in before you do any of this. You may also need to drop existing connections to the database. It could be that the script is waiting for exclusive access to the table before it does any work.
I am writing my first database application in c# and I have to use MS Access database, I have two tables Invoice and Order the order table is a child table. Invoice is a parent table it has key column "InvoiceNumber" which is auto column and it has a one to many relation with Order table column "InvoiceNumber". The problem I am having is that I got an exception at the line
tableAdapterManager.UpdateAll(database1DataSet);
when I try to add a new row and click save,
"You cannot add or change a record because a related record is required in table 'Invoice'."
I tried to search but I am unable to find it any help for ms access database, most of them are of SQL database. I also found one solution to edit the relation in the dataset designer to select the option "Both relation and foreign key constraints" but it didnot work for me either.
Thanks
Make sure that your OleDbParameters are properly set and in the correct corresponding order as the columns in the tables in the database. If you use Visual Studio automated code generation for data sources when you add a database, then drag and drop a table onto a form, check out the <database name>DataSet.Designer.cs file. It will teach you all you need to know.
Scenario: Client maintains financial/compliance record in a spreadsheet for each quarter of the year. Spreadsheet contains columns which are not static, they can change from quarter to quarter and will not be same the next year. They want a portal by which all the regional managers (of stores/franchise) can enter their data and at the end aggregated at the national level.
Issue: As you could have guessed, I want to develop the spreadsheet column into sql table with all the columns, but the issue is that they want to add new columns dynamically (for future quarters) via admin side. Thinking of providing a textbox (columnname), dropdown (sqltypes possible) and add button which will basically add the column. But the columns can grow and that's not the right option, I guess. Other alternative is, instead of adding columns, I can add it as rows and then use PIVOT to do the sql part.
If anyone of you have developed this kind of application, could you please aware me of any complications before I proceed further with my idea of adding rows instead of columns for adding fields for the reports dynamically. If anyone has got sample example or reference online, please divert me there.
Take a look at Umbraco. It's a cms that puts the concept of PIVOT into practice. (Actually I believe most CMS does).
Actually, I'd go so far as to suggest building that application of yours in Umbraco. You will need to customise it a bit, but you will have quite a bit of heavy lifting already done for you, such as authorisation, membership, and the schema/content mechanism.