p30_code
جمعه 09 تیر 1391, 19:16 عصر
قسمت : cmd.CommandText = con را خطا میگیره لطفا راهنمایی کنید
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=SALEHI-PC;Initial Catalog=eshap;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = con;
cmd.CommandText = "select * from Prouduct ";
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
پیغام خطا Error 1 Cannot implicitly convert type 'System.Data.SqlClient.SqlConnection' to 'string' C:\Users\salehi\Desktop\Lesson1\Default.aspx.cs 22 27 C:\...\Lesson1\
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=SALEHI-PC;Initial Catalog=eshap;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = con;
cmd.CommandText = "select * from Prouduct ";
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
پیغام خطا Error 1 Cannot implicitly convert type 'System.Data.SqlClient.SqlConnection' to 'string' C:\Users\salehi\Desktop\Lesson1\Default.aspx.cs 22 27 C:\...\Lesson1\