Hi,
I am made the program student information ..
but the some error arise in particular code ,When I am Click the newstudentbutton in that time the error is rise, please solve the problem and give me solution...
code..
1.App Configuration
<configuration>
<configsections>
<connectionstrings>
<add name="ConString" connectionstring="Data Source=ANAND;Initial Catalog=TEST;Integrated Security=True"
providerName ="System.Data.SqlClient"/>
</connectionstrings>
</configsections>
</configuration>
2.DB_ACCESS Class
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Studentinformation
{
class DB_Access
{
SqlConnection conn;
public DB_Access()
{
conn = DB_Connection.GetConnection();
}
public void add_student(string regNo, string fName, string Lname, string phoneNo)
{
if (conn.State.ToString() == "Closed")
{
conn.Open();
}
SqlCommand newCmd = conn.CreateCommand();
newCmd.Connection = conn;
newCmd.CommandType = CommandType.Text;
newCmd.CommandText = "insert into student values('" + regNo + "','" + fName + "','" + Lname + "','" + phoneNo + "',)";
newCmd.ExecuteNonQuery();
}
}
}
3.
class DB_Connection
{
public static SqlConnection NewCon;
public static string ConStr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
public static SqlConnection GetConnection()
{
NewCon = new SqlConnection(ConStr);
return NewCon;
}
}
4.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnAddNew_Click(object sender, EventArgs e)
{
frmNewStudent newstudent = new frmNewStudent();
newstudent.Show();
}
}