I am trying to insert data into database by using windows from application . I hosted it into console application . I am using .net remoting to invoke the method . My host is running without any problem and i also can run the windows form application without any problem . But problem is when i clicked the submit button to insert data i got error.I do not know why i am getting this error .
null reference exception.
Here is the Interface .
namespace IHelloRemotingService
{
public interface IHelloRemotingService
{
void Insert(string Name, string Address, string Email, string Mobile)
}
}
Here is the Implementation of the interface ..
public class HelloRemotingService : MarshalByRefObject , IHelloRemotingService.IHelloRemotingService
{
public void Insert(string Name, string Address, string Email, string Mobile)
{
string constr = ConfigurationManager.ConnectionStrings["StudentConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("AddNewStudent", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@Address", Address);
cmd.Parameters.AddWithValue("@EmailID", Email);
cmd.Parameters.AddWithValue("@Mobile", Mobile);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
Here is the screen shot of application .
Code for windows form application ..
namespace HelloRemotingServiceClient
{
public partial class InsertStudentData : Form
{
IHelloRemotingService.IHelloRemotingService client;
public InsertStudentData()
{
InitializeComponent();
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel);
client = (IHelloRemotingService.IHelloRemotingService)Activator.GetObject(
typeof(IHelloRemotingService.IHelloRemotingService), "tcp://localhost:500/Insert");
}
private void button1_Click(object sender, EventArgs e)
{
client.Insert(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
label5.Text = "Data is inserted ";
}
}
}
Here is the screen shot of errors messages .