*These
namespaces are must be required for SqlServer Connectivity in your web form:-
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
App.config File
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<appSettings>
<add key="ConnectionString" value="Data Source=PRADEEP-HP;Initial Catalog=Decofloore2;User
ID=User_006;Password=user006"/>
</appSettings>
</configuration>
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DemoWindowApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
string StrCon = ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection SqlCon = new SqlConnection(StrCon);
string SqlQuery = "Update
ShowOnePage set Name='" + textName.Text + "',Address='" +
textAddress.Text + "',MobileNo=" + textPhNo.Text + ",EmailID='" + textEmailId.Text + "',"+
"DOB='" + dateTimePicker1.Value.ToString() + "' where RegistrationId='" + textRegId.Text.Trim() + "'";
SqlCommand SqlComm = new SqlCommand(SqlQuery, SqlCon);
SqlCon.Open();
int affected;
affected =
SqlComm.ExecuteNonQuery();
if (affected > 0)
{
lblMsg.Text = "Update Record Successfully";
}
else
{
lblMsg.Text = "Record are not Updated";
}
}
private void btnReset_Click(object sender, EventArgs e)
{
textEmailId.Text = "";
textName.Text = "";
textPhNo.Text = "";
textAddress.Text = "";
lblMsg.Text = "";
textRegId.Text = "";
}
private void btnNext_Click(object sender, EventArgs e)
{
Form2 obj2 = new Form2();
obj2.Show();
this.Hide();
}
}
}
0 comments
Post a Comment