Insert data from forms into datasets

浪尽此生 提交于 2019-12-11 20:41:44

问题


I have a dataset set up with 3 fields, ID username and password. I want the user to type in a new username and passoword and this then gets saved back to the dataset. How do I take what has been typed in and save it into the data set?

So far this is the code I have

usersTableAdapters.UsersTableAdapter user = new usersTableAdapters.UsersTableAdapter();
user.usersDataTable usertable = user.GetData();

This allows me to connect to the data set although I am not sure how to take the values the user will enter in the input boxes and save them back to the dataset?


回答1:


A quick and dirty implementation of this would look like this:

DataSet ds = new DataSet();
ds.Tables.Add(textBox1.Text);  //I did this in Winforms so, your result may vary.
ds.Tables.Add(textBox2.Text);  //Same here.

if (ds.HasChanges())  //Check if the DataSet has changes.
   ds.AcceptChanges(); //If it does, commit them.


来源:https://stackoverflow.com/questions/16471253/insert-data-from-forms-into-datasets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!