Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Error 1 The event 'System.Web.UI.WebControls.BaseDataBoundControl.DataBound' can only appear on the left hand side of += or -= D:\my project\dmv\dmv\svf\Default.aspx.cs "
//Edit as per op's more detail
C#
SqlConnection con = new SqlConnection("Data Source=NSYS1\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True"); 
con.Open(); 
string strQuery = "select * from stv where rdate =@Textbox6.text"; 
SqlCommand cmd = new SqlCommand(strQuery); 
cmd.CommandType = CommandType.Text; 
SqlDataAdapter sda = new SqlDataAdapter(cmd); 
cmd.Parameters.AddWithValue("@rdate", TextBox6.Text); 
DataSet ds = new DataSet(); 
sda.Fill(ds); 
DataTable dt = new DataTable(); 
dt = ds.Tables[0]; 
gvuser.DataSource = dt; 
gvuser.DataBound(); 
con.Close();
Posted
Updated 24-Oct-13 20:35pm
v2
Comments
Harshil_Raval 25-Oct-13 2:16am    
Update your question with more detail.
Raghavendra Guptha 25-Oct-13 2:26am    
SqlConnection con = new SqlConnection("Data Source=NSYS1\\SQLEXPRESS;Initial Catalog=agfl;connect timeout=30;Integrated Security=True");
con.Open();
string strQuery = "select * from stv where rdate =@Textbox6.text";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@rdate", TextBox6.Text);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
gvuser.DataSource = dt;
gvuser.DataBound();
con.Close();
Harshil_Raval 25-Oct-13 2:35am    
On which line you are getting this exception?
Raghavendra Guptha 25-Oct-13 2:39am    
gvuser.databound();
Harshil_Raval 25-Oct-13 2:40am    
see this..
string strQuery = "select * from stv where rdate =@Textbox6.text";
replace @Textbox6.text with @rdate.

Add connection string in your web.config file like:
HTML
<add name="MyConnectionString" connectionString="Data Source=ServerName;initial catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />


Update your code to:
C#
SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
con.Open();
string strQuery = "select * from stv where rdate = @rdate";
SqlCommand cmd = new SqlCommand(strQuery, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@rdate", TextBox6.Text);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
gvuser.DataSource = dt;
gvuser.DataBound();
con.Close();


It worked for me. Check if it works for you too.
 
Share this answer
 
v2
Comments
Raghavendra Guptha 25-Oct-13 2:42am    
given the same error
Zafar Sultan 25-Oct-13 2:56am    
Check my updated solution.
What are You Trying to do
do you want to bind the grid if so use above code
C#
using (SqlConnection con = new SqlConnection(Your Connection String))
{
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.CommandText = Your Command Text;
        cmd.Connection = con;
        con.Open();
        GridView1.DataSource = cmd.ExecuteReader();
        GridView1.DataBind();
        con.Close();
    }
}


ASP.NET
<Columns>
                                <asp:BoundField HeaderText="Your Header" DataField="Name Of Column or Model" />
 </Columns>


Hope this Helps...
 
Share this answer
 
v2
Comments
Raghavendra Guptha 25-Oct-13 2:52am    
wroking ok but notshowing gridview in asp.net page
Vishal Pand3y 25-Oct-13 3:06am    
Can u show your Code of aspx page....
Raghavendra Guptha 25-Oct-13 8:08am    
<asp:GridView ID="gvuser" runat="server" AutoGenerateColumns="False" PageSize="10"
Width="1017px" Caption="Settlement vouchers Feeding Details" AllowPaging="true"
>
<columns>
<asp:TemplateField HeaderText="S.No">
<itemtemplate>
<asp:Label ID="label1" Visible="true" runat="server" Text='<%# Eval("sno") %>'>


<asp:TemplateField HeaderText="RDATE">
<itemtemplate>
<asp:Label ID="label2" Visible="true" runat="server" Text='<%# Eval("rdate") %>'>


<asp:TemplateField HeaderText="ACNO">
<itemtemplate>
<asp:Label ID="label3" Visible="true" runat="server" Text='<%# Eval("acno") %>'>


<asp:TemplateField HeaderText="NAME">
<itemtemplate>
<asp:Label ID="label4" Visible="true" runat="server" Text='<%# Eval("name") %>'>


<asp:TemplateField HeaderText="VNO">
<itemtemplate>
<asp:Label ID="label5" Visible="true" runat="server" Text='<%# Eval("vno") %>'>


<asp:TemplateField HeaderText="AMOUNT">
<itemtemplate>
<asp:Label ID="label6" Visible="true" runat="server" Text='<%# Eval("amt") %>'>


<asp:TemplateField HeaderText="EDATE">
<itemtemplate>
<asp:Label ID="label7" Visible="true" runat="server" Text='<%# Eval("edate") %>'>


<asp:TemplateField HeaderText="CHNO">
<itemtemplate>
<asp:Label ID="label8" Visible="true" runat="server" Text='<%# Eval("chno") %>'>



Vishal Pand3y 25-Oct-13 8:13am    
it seems to be fine but for better practice use BoundField instead of TemplateField
see my Updated Solution
I Think this is very useful to us:
---------------------------------------

1> http://docs.oracle.com/cd/E17952_01/refman-5.5-en/connector-net-tutorials-entity-framework-databinding-linq-entities.html[^]
 
Share this answer
 
replace your following code .....
C#
string strQuery = "select * from stv where rdate = @rdate";
SqlCommand cmd = new SqlCommand(strQuery, con);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("@rdate", TextBox6.Text);
DataSet ds = new DataSet();
sda.Fill(ds);



By-
C#
string strQuery = "select * from stv where rdate = "+"'"TextBox6.Text"'";
SqlCommand cmd = new SqlCommand(strQuery, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);



Hope This Helps!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900