3 Replies - 5849 Views - Last Post: 08 January 2009 - 04:16 AM Rate Topic: -----

#1 bunny20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-December 08

how to add the data in textboxes to the database

Post icon  Posted 05 January 2009 - 03:34 AM

I am new in C#....I want to add the data in my text box in my database...how will i do it in C#?
Is This A Good Question/Topic? 0
  • +

Replies To: how to add the data in textboxes to the database

#2 beatles1692  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 62
  • Joined: 03-December 08

Re: how to add the data in textboxes to the database

Posted 05 January 2009 - 05:07 AM

Hi
You can use Ado.net (a part of .net framework that is responsible for working with databases) and you can find some useful links here.
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: how to add the data in textboxes to the database

Posted 05 January 2009 - 11:01 AM

I would suggest starting with the tutorials.

SQL Basics in C#
Was This Post Helpful? 0
  • +
  • -

#4 bunny20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 29-December 08

Re: how to add the data in textboxes to the database

Posted 08 January 2009 - 04:16 AM

I'm doing a project right now...but since I'm new in C# I don't know how to add the data from ASP objects in the database.

I divided the project in 3 layers, namely: The Business Logic (API), the Core (the databases) and the other one is were the design is made;

Below is the code of API:

The administration side;

 
using System;
using System.Collections.Generic;
using System.Text;

namespace API
{
   
	
	public class Administration
	{
		#region adding users
		public static bool AddUser(User user)
		{
			
			return false;
		}
		#endregion

		#region deleting users
		public static bool DeleteUser(User user)
		{
			return false;
		}
		public static bool DeleteUser(string id)
		{
			return false;
		}
		#endregion

		#region modifying users

		#endregion
	}
}




the General (used for all users)

using System;
using System.Collections.Generic;
using System.Text;

namespace API
{
	#region user data
	public class User
	{
		private User(string userid, int usertypeid, string fn, string ln, string mn, string address, string gender, string schlyear, string username, string semester, string password, string age)
		{
			this.userid = userid;
			usertypeid = usertypeid;
			fName = fn;
			lName = ln;
			mName = mn;
			this.address = address;
			this.gender = gender;
			this.schoolYear = schoolYear;
			this.semester = semester;
			this.username = username;
			this.password = password;
			this.age = age;
		}

		private string userid;
		public string Userid
		{
			get { return userid; }
			//set { userid = value; }
		}

		private string usertypeid;
		public string Usertypeid
		{
			get { return usertypeid; }
			//set { usertypeid = value; }
		}

		private string fName;
		public string FName
		{
			get { return fName; }
			set { fName = value; }
		}

		private string lName;
		public string LName
		{
			get { return lName; }
			set { lName = value; }
		}

		private string mName;
		public string MName
		{
			get { return mName; }
			set { mName = value; }
		}

		private string address;
		public string Address
		{
			get { return address; }
			set { address = value; }
		}

		private string gender;
		public string Gender
		{
			get { return gender; }
			set { gender = value; }
		}

		private string userId;
		public string UserId
		{
			get { return userId; }
			set { userId = value; }
		}

		private string userTypeid;
		public string UserTypeid
		{
			get { return userTypeid; }
			set { userTypeid = value; }
		}

		private string schoolYear;
		public string SchoolYear
		{
			get { return schoolYear; }
			set { schoolYear = value; }
		}

		private string semester;
		public string Semester
		{
			get { return semester; }
			set { semester = value; }
		}

		private string username;
		public string Username
		{
			get { return username; }
			set { username = value; }
		}

		private string password;
		public string Password
		{
			get { return password; }
			set { password = value; }
		}

		private string age;
		public string Age
		{
			get { return age; }
			set { age = value; }
		}
	}
	#endregion



the instructor side:


using System;
using System.Collections.Generic;
using System.Text;

namespace API
{
	class InstructorOperator
	{











	}
}




the studentoperation

using System;
using System.Collections.Generic;
using System.Text;

namespace API
{
	public class StudentOperations
	{
		//List<Question> Load(string topicId, string subjectId)
		//{
		//}

	}
}




the Core (or databases)


using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;


namespace Core
{
	public class TestClass
	{
		#region sample code
		public static List<string> TestQuery()
		{
			List<string> strings = new List<string>();
			string conStr = ConfigurationManager.AppSettings["defaultConnectionString"];
			SqlConnection connection = new SqlConnection(conStr);
			connection.Open();
			SqlCommand cmd = new SqlCommand("SELECT * FROM [User]",connection);

			SqlDataReader dataReader =  cmd.ExecuteReader();
			//while (dataReader.Read())
			//{
			//	strings.Add(dataReader["UserId"].ToString() + " - " + dataReader["UserName"].ToString());
			//}
		   // SqlCommand cmd2 = new SqlCommand("UPDATE [User] Set Username = 'wewe2' where username='wewe' ", connection);
			cmd.ExecuteNonQuery();
			connection.Close();
			return strings;
		}
		#endregion
		
		#region add user
		public static List<string> adduser()
		{
			List<string> strings = new List<string>();
			string conStr = ConfigurationManager.AppSettings["defaultConnectionString"];
			SqlConnection connection = new SqlConnection(conStr);
			connection.Open();

			SqlCommand cmd2 = new SqlCommand ( "INSERT INTO [User](UserId, UserTypeId, UserName, FirstName, LastName, MiddleName, SchYear, Semester, Password, Gender, Address, Age",connection);
			cmd2.ExecuteNonQuery();
			connection.Close();
			return strings;

		}
		#endregion




below is one of the source code for administration side:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Core;
using API;

public partial class Default2 : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{

	}
	protected void fnametextbox_TextChanged(object sender, EventArgs e)
	{

	}
	protected void UsersGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
	{
		thesis.ConnectionString = "JOJO; Integrated Security=SSPI; Initial Catalog=juv";

		
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
	   
	}
	protected void saveButton_Click(object sender, EventArgs e)
	{

	}
}




This is an object-oriented type of program. This is an online examination. Please help me....



sorry. but that code have errors too! please understand...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1