hope will replay my post.thank you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString"].ConnectionString;
}
private void ExecuteInsert(string customer_id, string name, string gender, string calculate, string address, string nationality, string email, string mobile, string license, string rentdate, string returndate, string total)
{
SqlConnection conn = new SqlConnection (GetConnectionString());
string sql = "INSERT INTO rental (customer_id, name, gender, address, nationality, email, mobile, license, rentdate, returndate, calculate, total) VALUES " + " (customer_id, name, gender, address, nationality, email, mobile, license, rentdate, returndate, calculate, total)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[12];
param[0] = new SqlParameter("@customer_id",SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@name", SqlDbType.VarChar, 50);
param[2] = new SqlParameter("@gender", SqlDbType.VarChar, 50);
param[3] = new SqlParameter("@address", SqlDbType.VarChar, 50);
param[4] = new SqlParameter("@nationality", SqlDbType.VarChar, 50);
param[5] = new SqlParameter("@email", SqlDbType.VarChar, 50);
param[6] = new SqlParameter("@mobile", SqlDbType.VarChar, 50);
param[7] = new SqlParameter("@licence", SqlDbType.VarChar, 50);
param[8] = new SqlParameter("@rentdate", SqlDbType.VarChar, 50);
param[9] = new SqlParameter("@returndate", SqlDbType.VarChar, 50);
param[10] = new SqlParameter("@calculate", SqlDbType.VarChar, 50);
param[11] = new SqlParameter("@total", SqlDbType.VarChar, 50);
param[0].Value = customer_id;
param[1].Value = name;
param[2].Value = gender;
param[3].Value = address;
param[4].Value = nationality;
param[5].Value = email;
param[6].Value = mobile;
param[7].Value = license;
param[8].Value = rentdate;
param[9].Value = returndate;
param[10].Value = calculate;
param[11].Value = total;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void btnsave_Click(object sender, EventArgs e)
{
ExecuteInsert(txtcustomer_id.Text, txtname.Text, txtgender.Text, txtaddress.Text, txtnationality.Text, txtemail.Text, txtmobile.Text, txtlicence.Text, txtrentdate.Text, txtreturndate.Text, txtcalculate.Text, txttotal.Text);
Response.Write("Record was succesfully added!");
}
protected void txtcalculate_TextChanged(object sender, EventArgs e)
{
}
}

New Topic/Question
Reply




MultiQuote






|