Hello Sir,
I have already passed the dtaa source but then also im getting this error .
Getting this error: A data source instance has not been supplied for the data source DataSet1.
please help me out.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string com = "select client_Id,preferredname from client where rowstate=1 ";
SqlDataAdapter adpt = new SqlDataAdapter(com, con);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList4.DataSource = dt;
DropDownList4.DataBind();
DropDownList4.DataTextField = "preferredname";
DropDownList4.DataValueField = "client_Id";
DropDownList4.DataBind();
DropDownList4.Items.Insert(0, new ListItem("------Select Client-----", "0"));
}
}
protected void btn1_Click(object sender, EventArgs e)
{
ReportViewer1.Visible = true;
int id = Convert.ToInt32(txtID.Text);
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/report.rdlc");
DataSet ds = new DataSet();
ds = GetData(id);
if (ds.Tables[0].Rows.Count > 0)
{
ReportViewer1.Reset();
ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
}
}
private DataSet GetData(int id)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from client where client_Id=" + id + " and rowstate=1");
using (con)
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
cmd.Connection = con;
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
return (ds);
}
}
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{
txtID.Visible = true;
String strQuery = "select client_Id,preferredname from client where" +
" client_Id = @client_Id and rowstate=1";
SqlCommand cmd = new SqlCommand();
cmd.Parameters.AddWithValue("@client_Id", DropDownList4.SelectedItem.Value);
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
cmd.Connection = con;
try
{
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
txtID.Text = sdr[0].ToString();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}