How to display value from SQL Server database in input box? - c#

I would like to do something like simple data binding in Windows Forms, but in Web Forms. So I would like to get data from a column NAME from table CATS (one row) and display in on website in text box (input type='text') and next I would like to click on "save" button to save this data to database doing an update.
Could you please give me a short snippet of how should I do it to work and get understanding of how does it go?

Really easy updating can come through the detailsview control: https://web.archive.org/web/20211020133929/https://www.4guysfromrolla.com/articles/050207-1.aspx

Related

ASP.NET GridView with 'Save All' feature

Scenario : I wanted to provide a GridView where the user can enter data row by row and display it(I did not bind to a database yet). I gave a footer where the user enters data and clicks add to add the data to the GridView. Finally, I gave a 'Save All' button to save the whole GridView data to the database.
What I did : I implemented it in this way where the data gets saved to an XML file when each row is added to the GridView. When the user clicks 'Save All' all the data in the file gets saved in the database. This implementation works perfectly.
My Question : My problem was that I found this implementation a bit complex and so i want to know if there are any other ways to do this(Javascript/jquery or any other). Any ideas/suggestions/links/sample codes are welcome.
Thanks a lot for your response guys. I used the Obout grid(Excel style) to achieve it. It works just as I wanted.

make an interface with datagrid

I am making a windows form application, a billing software. I want to make a interface like this on one of the forms:
There is a row of textboxes with about 5-7 textboxes, i fill the first textbox with a product ID which automatically populates the rest of the textboxes fetching data from appropriate tables and automatically generate a new row of textboxes, the first textbox from the new row being focussed for entering product ID. It should continue until i click a certain button which finalizes the bill. On clicking this button all these values should be updated to database in respective tables. How can I achieve this?
Can using datagrid help?
Google "C# write to database" and click on one of the links, like these that came up when I did it:
http://www.codeproject.com/Articles/3554/Simple-Database-Application-Part-1
http://www.codeproject.com/Articles/1155/Simple-ADO-NET-Database-Read-Insert-Update-and-Del
Or go to amazon.com and search "c# database" and buy one of those books.

Update a data row inside an asp.net Data Grid View

I think it would be easier for you to understand my problem if I explain the scenario a bit.
What I am doing is developing a system to a doctor using asp.net c#. For the creation of the prescription, I add a check box list for the list of medicines and submit button below it. When the submit button clicked selected check box list items added to the sql server database and show a data grid with the selected medicines in the same page.
In the data grid there are two columns for medicine name and dosage.Medicine name is taken from the database.I need to give the user the ability to enter the dosage through that grid view. I need to use update command because the record is already there in the sql server.But empty value in the dosage column.I tried to use update command in the data source control. But I can't figure out how to give the WHERE clause because I can't specify the database row which the updating record relate to.
I would be glad to hear some help from you. All the comments are welcome.
You need to set a parameter(s), please check this example to understand how it works. I guess, that you've added in the database some column that is unique identifier.. some autoincrement int or guid.

work with data grid view in C# windows forms

Dear sir,
I m developing one application on c# windows forms by using OLEDB connection.On that one form i placed one datagridview and bind to one table.That table contains some fields....., here my problem is i want to edit table on runtime.On that table i need two links as edit,unmask.In runtime data in datagridview is seems to plain text on paper.if we click edit that row changed to text boxes and combo boxes.Sometext boxes contain passwords also.those are in ** formate.while picking unmask button those passwords are changed to actual text.while picking edit button that exploted to update, cancel.Then we change the data and pick update then data stored to database table.(i need datagridview as gridview in ASP.Net).Is there any properties for datagridview as gridview(ASP).Could you please suggest me how to resolve my prob.
Thanks in advance.
Can you, at the time of the hang, hit pause in Visual Studio to see where your code hangs?

Adding rows to a table based on user input (ASP.NEt)

I have a TextBox entry field where the user will enter a integer value. And then there is a "Create" button, which when clicked upon must generate a Table with 2 columns :
"Name" and "Email" being the column headers.
I want each row to have a textbox in each of these columns.
All of this has to happen after the button is clicked. I have discovered that if you dynamically add a control in ASP.NET(I am using C#) then the controls are lost during postback. And I don't know how to prevent that from happening.
Can somebody please give me some ideas regarding how to go about adding rows dynamically to a table (I tried using the asp.net Server side table control but ran into the "lost-during-postback" problem - can I try with something else like a gridview ? but afaik a GV will not work without data bound to it )
Point to note is that my table has textboxes for user entry and it is not for showing data ..rather it is for accepting data from the user which will be later used to persist details to the database.
Dynamic Controls
That's involved. Here's an interesting article on the issue of dynamic controls.
I think normally if you create dynamic controls then you're responsible for recreating them on postback; however the article contains a way to use the Init event if it's copacetic with your app.
Edit:
or Regular ASP.NET Controls
You can use data bound ASP.NET controls like: DataList, Repeater, GridView, etc. (You can put text boxes and all other kinds of controls into them for repeating in each row - or "item") and bind values to it. If you need to perform some processing on the user input first, then generate an internal Array, List, Dictionary, DataTable etc. (your choice) and bind that data as a data source to the ASP.NET control of choice.
aspnetControl.DataSource = myDataTable;
aspnetControl.DataBind();
or
aspnetControl.DataSourceId = "name_of_control";
There are various ways to assign a data source.
This way you won't run into the same problems as with dynamic control creation; however there is a lot to learn to facilitate this way too.

Categories

Resources