0% found this document useful (0 votes)
14 views

Connection Code

The document contains C# code for a web form that connects to a SQL database and inserts registration data into a table when a button is clicked if all text boxes are filled. It catches any exceptions and displays them.

Uploaded by

Amitha Joy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Connection Code

The document contains C# code for a web form that connects to a SQL database and inserts registration data into a table when a button is clicked if all text boxes are filled. It catches any exceptions and displays them.

Uploaded by

Amitha Joy
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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;

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = "Data Source=LAPTOP-
NLE0TS20\\SQLEXPRESS01;Initial Catalog=testdatabase;Integrated Security=True";
con.Open();
}

protected void Button2_Click(object sender, EventArgs e)


{
try
{
if(TextBox1.Text!= "" && TextBox2.Text!= "" && TextBox3.Text!= ""
&& TextBox4.Text!= "" && TextBox5.Text!= "" && TextBox6.Text != "" && TextBox5.Text
!= "")
{
SqlCommand cmd = new SqlCommand("insert into registrationtb" +
"(R_isbn,R_title,R_author,R_pubname,R_email,R_password,R_confirmpass)values(@R_isbn
,@R_title,@R_author,@R_pubname,@R_email,@R_password,@R_confirmpass)", con);
cmd.ExecuteNonQuery();
Response.Write(" <script language='javascript'>
alert('Registration Successful..')</script>");
}

}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "');</script>");
}

}
}
}

You might also like