PDA

View Full Version : مشکل در ارتباط با دیتا بیس



Arezoo62
پنج شنبه 15 تیر 1391, 10:18 صبح
بچه ها من دقیقا با همین کد تو دفعه های قبل اطلاعات فرم و میریختم تو دیتا بیس اما الان
این ارور میده
Invalid object name 'Contact'.

SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=،TestProject;Integrated Security=True");
SqlCommand cmd;
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Insert Into [Contact] Values (N'" + txtName.Text + "', N'" + txtEmail.Text + "', N'" + lstSubject.Text + "', N'" + txtInfo.Text + "', N'" + txtInfo.Text + "')";
if (con.State != ConnectionState.Open)
{
con.Open();
}
if (cmd.ExecuteNonQuery() == 0)
{
lblError.Text = "خطا - در ارسال اطلاعات مشکلی پدید آمده است";
}
con.Close();

TeacherMath
پنج شنبه 15 تیر 1391, 10:28 صبح
Data Source=.;Initial Catalog=TestProject;Integrated Security=True

Arezoo62
پنج شنبه 15 تیر 1391, 11:21 صبح
دوست عزیز این کانکشن استرینگ موجود تو web config است:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\asp netdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>


اینم کدم:
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TestProject;Integrated Security=True");
SqlCommand cmd;
cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Insert Into [Contact] Values (N'" + txtName.Text + "', N'" + txtEmail.Text + "', N'" + lstSubject.Text + "', N'" + txtInfo.Text + "', N'" + txtInfo.Text + "')";
if (con.State != ConnectionState.Open)
{
con.Open();
}
if (cmd.ExecuteNonQuery() == 0)
{
lblError.Text = "خطا - در ارسال اطلاعات مشکلی پدید آمده است";
}
con.Close();


به contact گیر میده
و این قسمت و ارور میگیره:
if (cmd.ExecuteNonQuery() == 0)