473,804 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet was removed automatically?

Tom
Hi,

Here is my C# code for a simple web logon form:

After I added the sqlDataAdapter1 , sqlConnection1,
dataSet1 and compile the program, there was build error
which said it did not find dataSet1. When I saw the aspx
design page, the DataSet11 was disappeared.

Were my steps wrong? And, where can I find a simple
example to test the connection with ms sql server with
asp.net?

Thanks

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. namespace sampleapplication
  13. {
  14. /// <summary>
  15. /// Summary description for WebForm1.
  16. /// </summary>
  17. public class sampleapplication : System.Web.UI.Page
  18. {
  19. protected System.Web.UI.WebControls.Label
  20. Label2;
  21. protected System.Web.UI.WebControls.Label
  22. Label3;
  23. protected
  24. System.Web.UI.WebControls.TextBox txtUserName;
  25. protected
  26. System.Web.UI.WebControls.TextBox txtPassword;
  27. protected System.Web.UI.WebControls.Button
  28. btnSubmit;
  29. protected
  30. System.Web.UI.WebControls.RequiredFieldValidator
  31. RequiredFieldValidator1;
  32. protected
  33. System.Web.UI.WebControls.RequiredFieldValidator
  34. RequiredFieldValidator2;
  35. protected System.Web.UI.WebControls.Label
  36. lblMessage;
  37. protected
  38. System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
  39. protected System.Data.SqlClient.SqlCommand
  40. sqlSelectCommand1;
  41. protected System.Data.SqlClient.SqlCommand
  42. sqlInsertCommand1;
  43. protected System.Data.SqlClient.SqlCommand
  44. sqlUpdateCommand1;
  45. protected System.Data.SqlClient.SqlCommand
  46. sqlDeleteCommand1;
  47. protected
  48. System.Data.SqlClient.SqlConnection sqlConnection1;
  49. protected sampleapplication.DataSet1
  50. dataSet11;
  51. protected System.Web.UI.WebControls.Label
  52. Label1;
  53.  
  54.  
  55. private void Page_Load(object sender,
  56. System.EventArgs e)
  57. {
  58. // Put user code to initialize the
  59. page here
  60. }
  61.  
  62. #region Web Form Designer generated code
  63. override protected void OnInit(EventArgs e)
  64. {
  65. //
  66. // CODEGEN: This call is required
  67. by the ASP.NET Web Form Designer.
  68. //
  69. InitializeComponent();
  70. base.OnInit(e);
  71. }
  72.  
  73. /// <summary>
  74. /// Required method for Designer support -
  75. do not modify
  76. /// the contents of this method with the
  77. code editor.
  78. /// </summary>
  79. private void InitializeComponent()
  80. {
  81. this.sqlDataAdapter1 = new
  82. System.Data.SqlClient.SqlDataAdapter();
  83. this.sqlDeleteCommand1 = new
  84. System.Data.SqlClient.SqlCommand();
  85. this.sqlConnection1 = new
  86. System.Data.SqlClient.SqlConnection();
  87. this.sqlInsertCommand1 = new
  88. System.Data.SqlClient.SqlCommand();
  89. this.sqlSelectCommand1 = new
  90. System.Data.SqlClient.SqlCommand();
  91. this.sqlUpdateCommand1 = new
  92. System.Data.SqlClient.SqlCommand();
  93. this.dataSet11 = new
  94. sampleapplication.DataSet1();
  95.  
  96. ((System.ComponentModel.ISupportInitialize)
  97. (this.dataSet11)).BeginInit();
  98. this.btnSubmit.Click += new
  99. System.EventHandler(this.btnSubmit_Click);
  100. //
  101. // sqlDataAdapter1
  102. //
  103. this.sqlDataAdapter1.DeleteCommand
  104. = this.sqlDeleteCommand1;
  105. this.sqlDataAdapter1.InsertCommand
  106. = this.sqlInsertCommand1;
  107. this.sqlDataAdapter1.SelectCommand
  108. = this.sqlSelectCommand1;
  109.  
  110. this.sqlDataAdapter1.TableMappings.AddRange(new
  111. System.Data.Common.DataTableMapping[] {
  112.  
  113.  
  114.  
  115. new
  116. System.Data.Common.DataTableMapping("Table", "logon", new
  117. System.Data.Common.DataColumnMapping[] {
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. new System.Data.Common.DataColumnMapping
  126. ("username", "username"),
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. new System.Data.Common.DataColumnMapping
  135. ("password", "password")})});
  136. this.sqlDataAdapter1.UpdateCommand
  137. = this.sqlUpdateCommand1;
  138. //
  139. // sqlDeleteCommand1
  140. //
  141. this.sqlDeleteCommand1.CommandText
  142. = "DELETE FROM logon WHERE (username = @Original_username)
  143. AND (password = @Original" +
  144. "_password)";
  145. this.sqlDeleteCommand1.Connection
  146. = this.sqlConnection1;
  147.  
  148. this.sqlDeleteCommand1.Parameters.Add(new
  149. System.Data.SqlClient.SqlParameter("@Original_username",
  150. System.Data.SqlDbType.VarChar, 10,
  151. System.Data.ParameterDirection.Input, false, ((System.Byte)
  152. (0)), ((System.Byte)(0)), "username",
  153. System.Data.DataRowVersion.Original, null));
  154.  
  155. this.sqlDeleteCommand1.Parameters.Add(new
  156. System.Data.SqlClient.SqlParameter("@Original_password",
  157. System.Data.SqlDbType.VarChar, 10,
  158. System.Data.ParameterDirection.Input, false, ((System.Byte)
  159. (0)), ((System.Byte)(0)), "password",
  160. System.Data.DataRowVersion.Original, null));
  161. //
  162. // sqlConnection1
  163. //
  164.  
  165. this.sqlConnection1.ConnectionString = "data
  166. source=SERVER;initial catalog=sampledatabase;persist
  167. security info=Fal" +
  168. "se;user id=sa;workstation
  169. id=SERVER;packet size=4096";
  170. //
  171. // sqlInsertCommand1
  172. //
  173. this.sqlInsertCommand1.CommandText
  174. = "INSERT INTO logon(username, password) VALUES
  175. (@username, @password); SELECT usern" +
  176. "ame, password FROM logon
  177. WHERE (username = @username)";
  178. this.sqlInsertCommand1.Connection
  179. = this.sqlConnection1;
  180.  
  181. this.sqlInsertCommand1.Parameters.Add(new
  182. System.Data.SqlClient.SqlParameter("@username",
  183. System.Data.SqlDbType.VarChar, 10, "username"));
  184.  
  185. this.sqlInsertCommand1.Parameters.Add(new
  186. System.Data.SqlClient.SqlParameter("@password",
  187. System.Data.SqlDbType.VarChar, 10, "password"));
  188. //
  189. // sqlSelectCommand1
  190. //
  191. this.sqlSelectCommand1.CommandText
  192. = "SELECT username, password FROM logon WHERE (username =
  193. @username)";
  194. this.sqlSelectCommand1.Connection
  195. = this.sqlConnection1;
  196.  
  197. this.sqlSelectCommand1.Parameters.Add(new
  198. System.Data.SqlClient.SqlParameter("@username",
  199. System.Data.SqlDbType.VarChar, 10, "username"));
  200. //
  201. // sqlUpdateCommand1
  202. //
  203. this.sqlUpdateCommand1.CommandText
  204. = "UPDATE logon SET username = @Param1, password =
  205. @password WHERE (username = @Orig" +
  206. "inal_username) AND
  207. (password = @Original_password); SELECT username, password
  208. FR" +
  209. "OM logon WHERE (username
  210. = @username)";
  211. this.sqlUpdateCommand1.Connection
  212. = this.sqlConnection1;
  213.  
  214. this.sqlUpdateCommand1.Parameters.Add(new
  215. System.Data.SqlClient.SqlParameter("@Param1",
  216. System.Data.SqlDbType.VarChar, 10, "username"));
  217.  
  218. this.sqlUpdateCommand1.Parameters.Add(new
  219. System.Data.SqlClient.SqlParameter("@password",
  220. System.Data.SqlDbType.VarChar, 10, "password"));
  221.  
  222. this.sqlUpdateCommand1.Parameters.Add(new
  223. System.Data.SqlClient.SqlParameter("@Original_username",
  224. System.Data.SqlDbType.VarChar, 10,
  225. System.Data.ParameterDirection.Input, false, ((System.Byte)
  226. (0)), ((System.Byte)(0)), "username",
  227. System.Data.DataRowVersion.Original, null));
  228.  
  229. this.sqlUpdateCommand1.Parameters.Add(new
  230. System.Data.SqlClient.SqlParameter("@Original_password",
  231. System.Data.SqlDbType.VarChar, 10,
  232. System.Data.ParameterDirection.Input, false, ((System.Byte)
  233. (0)), ((System.Byte)(0)), "password",
  234. System.Data.DataRowVersion.Original, null));
  235.  
  236. this.sqlUpdateCommand1.Parameters.Add(new
  237. System.Data.SqlClient.SqlParameter("@username",
  238. System.Data.SqlDbType.VarChar, 10, "username"));
  239. //
  240. // dataSet11
  241. //
  242. this.dataSet11.DataSetName
  243. = "DataSet1";
  244. this.dataSet11.Locale = new
  245. System.Globalization.CultureInfo("zh-CN");
  246. this.dataSet11.Namespace
  247. = "http://www.tempuri.org/DataSet1.xsd";
  248. this.Load += new
  249. System.EventHandler(this.Page_Load);
  250.  
  251. ((System.ComponentModel.ISupportInitialize)
  252. (this.dataSet11)).EndInit();
  253.  
  254. }
  255. #endregion
  256.  
  257. private void btnSubmit_Click(object
  258. sender, System.EventArgs e)
  259. {
  260. sqlConnection1.Open();
  261.  
  262. sqlDataAdapter1.SelectCommand.Parameters
  263. [0].Value=txtUserName.Text.Trim();
  264. sqlDataAdapter1.Fill
  265. (dataSet11, "UserDetails");
  266. if (dataSet11.Tables
  267. ["UserDetails"].Rows.Count==0)
  268. {
  269. lblMessage.Text="Invalid
  270. user name";
  271. }
  272. else
  273. {
  274. if (dataSet11.Tables
  275. ["UserDetails"].Rows[0][1].ToString().Trim()
  276. ==txtPassword.Text.Trim())
  277.  
  278. lblMessage.Text="Welcome + " + txtUserName.Text;
  279. else
  280.  
  281. lblMessage.Text="Invalid PASSWORD";
  282. }
  283. sqlConnection1.Close();
  284. }
  285. }
  286. }
  287.  

Nov 15 '05 #1
0 1016

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
749
by: Bruce Stockwell | last post by:
the setup: Webservice/WinClient application/SQL server. VS.Net (visual basic) winform wizard creates a simple form with load cancel cancelall and datagrid bound to a simple Dataset with one Datatable. No coding by programer, All wizardry. User starts app, opens form, adds (4) records and clicks update.
2
1783
by: Arthur Dzhelali | last post by:
I have a two xml files schema is identical. When I read file into dataset and then bind dataset to the form. These are weather files we are getting from weather service. One file has only local weather so I don't have any problems with that, but other has weather for several different locations. Basically I need to select only weather for location if I know its code. I should have exactly same dataset so I will be able bind it to the...
5
7034
by: Cybertof | last post by:
Hello, Is it necessary to initially fill a dataset to be able to add a new row to the dataset and then update the undercover database ? (In the case of a very large database, this would mean that all the database content should be loaded before beeing able to add a new row, and i don't want to load anything...) Is it possible in the following code to remove the "// CAN THIS BE REMOVED ?"
1
8591
by: Fleckman | last post by:
I have a situation where I need to add rows to tables with a Parent-Child relationship which presents a constraints violation when I reject the changes. Here is the scenario: I add a row to a Parent table which then causes a row to be added to the Child table referencing the parent row. The Child table rows can be modified by multiple processes so I need to manage row additionals separate from row modifications in terms of how they are...
2
4829
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different row selected in the datagrid. I want to save the changes that user make in the textboxes when they select a different row in the datagrid. I tried capturing the textbox.text at datagrid's CurrentCellChanged event but by then the textbox.text...
1
1691
by: PartyFears | last post by:
Dear All, I have the following problem. I have populated a datasset and bound the contents to varous text fields defined in a page. I do this through running Me.Databind in the Form_Load of the page concerned. The dataset will only contain one table and one row within the table. Up to this point everything is OK.
3
15729
by: Stephen | last post by:
I have a dataset that I do not want written back to the table. I need to delete rows from the dataset where to fields are equal...example Dataset1 bridge <---- pk amt rec if amt =rec , i want to delete / remove the record but cant figure it out
4
1198
by: Tina | last post by:
The docs I am reading says that the dataset/datatable are no longer supported in vs.net 2005 and .net 2.0. There were lots of great things the dataset allowed us to do that I don't see a replacement for. For instance I found the best way to produce a crystalreport was to source it from an XML dataset that was created by a myDataSet.WriteXml call. Is this kind of ability lost? (no longer supported?) Thanks, T
1
2540
by: matt | last post by:
hello, i have a web app that allows users to query our oracle db and produce a dataset of report data. they then have the option to serialize this data and store it in the database. later, then can re-run the report and get fresh data. now, they would like to be able to compare the fresh data to the stored data, getting a break-down of added/deleted/changed rows. on the surface, this sounded plausible -- by deserializing the stored
8
11103
by: cj | last post by:
I have a program to display queries to a SQL db. I type my query in a textbox and click a button and the results display in a datagrid. I could use either dataset or datatable to read the data in then I make the datagrid.datasource = myds.Tables(0) or mydt. Now what I want is to be able to change the query and click the button again and get the new results. I can use clear() to clear the data from a ds/dt but I need the structure gone...
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9171
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.