adamak88
26-07-2008, 07:25
System.InvalidOperationException was unhandled
Message="ExecuteNonQuery: Connection property has not been initialized
از sqlcmmand وsqlconnection برای وصل شدن به sql server استفاده کردم
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace PERSONEL
{
class JOBS
{
public void InsJobs(string JOBTITLE)
{
SqlCommand cmd=new SqlCommand();
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="InsJobs";
cmd.Parameters.AddWithValue("@JOBTITLE",JOBTITLE);
MyDbRun dbrun=new MyDbRun();
dbrun.ExeCommand(cmd);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace PERSONEL
{
class MyDbRun
{
string ConStr = "server=(local);database=ACCWAGE;integrated security=true";
SqlConnection MyCn;
//
public MyDbRun()
{
MyCn = new SqlConnection(ConStr);
}
//
public void ExeCommand(SqlCommand MyCmd)
{
if (MyCn.State == ConnectionState.Closed)
{
MyCn.Open();
}
***********************************************
MyCmd.ExecuteNonQuery();:41::41:
************************************************** *
MyCn.Close();
MyCn.Dispose();
}
//
}
}
در database یک table به اسم JOBS و یک stored procedure به اسم InsJobs دارم
نمیدونم چرا این exeption میده
؟؟؟؟
Message="ExecuteNonQuery: Connection property has not been initialized
از sqlcmmand وsqlconnection برای وصل شدن به sql server استفاده کردم
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace PERSONEL
{
class JOBS
{
public void InsJobs(string JOBTITLE)
{
SqlCommand cmd=new SqlCommand();
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="InsJobs";
cmd.Parameters.AddWithValue("@JOBTITLE",JOBTITLE);
MyDbRun dbrun=new MyDbRun();
dbrun.ExeCommand(cmd);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace PERSONEL
{
class MyDbRun
{
string ConStr = "server=(local);database=ACCWAGE;integrated security=true";
SqlConnection MyCn;
//
public MyDbRun()
{
MyCn = new SqlConnection(ConStr);
}
//
public void ExeCommand(SqlCommand MyCmd)
{
if (MyCn.State == ConnectionState.Closed)
{
MyCn.Open();
}
***********************************************
MyCmd.ExecuteNonQuery();:41::41:
************************************************** *
MyCn.Close();
MyCn.Dispose();
}
//
}
}
در database یک table به اسم JOBS و یک stored procedure به اسم InsJobs دارم
نمیدونم چرا این exeption میده
؟؟؟؟