I am new to net developing and have managed to work my way through a lot of questions I have had just by looking through the forums.
It appears that the issue that I am having is something that a number of others have had I have found that they are all different and just haven't for the life of me been able to work through it.
I am trying to insert player registration details into database but when I try to invoke the wcf server it am met with the exception type on my conn.Open():
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code.
In addition I am using the build it sql server and the connection string used is one from properties on the database. I am not too sure how to proceed.
public string playerRegistration(playerDetails playerInfo)
{
string Message;
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\\Users\\Daniel\\documents\\visual studio 2013\\Projects\\Prac4\\WebApplication1\\App_Data\\ADODatabase.mdf;Integrated Security=True"))
{
conn.Open();
using (var cmd = new SqlCommand("INSERT into Player(pid, pfname, plname, pphone, paddress, pdob) VALUES (@pid, @pfname, @plname, @pphone, @paddress, @pdob)", conn))
{
cmd.Parameters.AddWithValue("@pid", playerInfo.Pid);
cmd.Parameters.AddWithValue("@pfname", playerInfo.Pfname);
cmd.Parameters.AddWithValue("@plname", playerInfo.Plname);
cmd.Parameters.AddWithValue("@pphone", playerInfo.Pphone);
cmd.Parameters.AddWithValue("@paddress", playerInfo.Paddress);
cmd.Parameters.AddWithValue("@pdob", playerInfo.Pdob);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
Message = " Details inserted successfully";
}
else
{
Message = " Details not inserted successfully";
}
conn.Close();
return Message;
}
}
}