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#?
how to add the data in textboxes to the database
Page 1 of 13 Replies - 4630 Views - Last Post: 08 January 2009 - 04:16 AM
Replies To: how to add the data in textboxes to the database
#3
Re: how to add the data in textboxes to the database
Posted 05 January 2009 - 11:01 AM
#4
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;
the General (used for all users)
the instructor side:
the studentoperation
the Core (or databases)
below is one of the source code for administration side:
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...
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...
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|