473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Gridview filling at runtime

Hi!
I want to fill the GridView at Runtime.
For that I am using the following code:
Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Dmo_SubConnectionString"].ConnectionString);
  2. string str = 
  3. "SELECT M.Pat_Id, M.Pat_First, R.Reg_ID, R.Ent_Date, M.Emp_Name FROM PAT_REG AS R INNER JOIN PAT_MAST AS M ON R.Pat_ID = M.Pat_Id WHERE R.Ent_Date BETWEEN '" + 
  4.   drtextbox1.Text + 
  5.   "' AND '" + 
  6.   drtextbox2.Text + "'";
  7.  
  8. DataSet ds = new DataSet();
  9. con.Open();
  10. SqlDataAdapter da = new SqlDataAdapter(str, con);
  11. da.Fill(ds);
  12. GridView1.DataSource = ds.Tables[0];
  13. GridView1.DataBind();
Then no error is occur and no output is occur.
What I do?
Please help me.

Thanks in advance.
Oct 25 '11 #1
1 1788
Frinavale
9,735 Expert Mod 8TB
It sounds like you aren't retrieving any data from your database.

Try doing SELECT * FROM PAT_REG to see if you get any data.

You should not be inserting text that the user provided into your SQL queries. This leaves you open to something called an Insertion Attack (or Injection Attack).

Create a SqlCommand object for your query. Supply your query to the SqlCommand and use the SqlCommand's Parameters property to add the input that the user provided to the query. The SqlCommand will then treat the user's input as "Literal" data instead of part of the command (as you have it)

Set the SqlDataAdapter.SelectCommand Property to the SqlCommand you have instantiated and configured it.

-Frinny
Oct 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark Parter | last post by:
I have a GridView control which is bound to a Stored Procedure (SP) using a SQLDataSource. The problem I'm having is that the SP returns 4 known columns and x amount of unknown columns. I can...
2
by: mangomadman | last post by:
Has anyone solved the problem with adding Controls dynamically to a GridView at runtime? I encounter the problem that GridView doesn't save these Controls on post back, which makes them useless.
4
by: Eamonn | last post by:
Hi I am running Microsoft Visual Studio 2005 Team Edition Version 8.0.50727.42. I am adding columns to a GridView at runtime. When I add a BoundField that will contain DateTime data I want to...
2
by: VMI | last post by:
I'm filling up a gridview and the underlying datatable has about 30,000 records, so it takes some time before I can see the page again with the records on the gridview. Is there any type of...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
0
by: Adam Sandler | last post by:
Hello, My codebehind builds a GridView at runtime and shovels the data off as a part of a callback... Dim returnstring As String = String.Empty Dim gv As New GridView gv.DataSource = ds...
0
by: shapper | last post by:
Hello, I have created a GridView on runtime by implementing the ITemplate class. This Gridview displays a list of articles. Each article has a Title, Content and PubDate. I am trying to...
1
by: ElizabethS | last post by:
Hi, I am trying to bind to a gridview during runtime, but its not working. The DataSourceID of the Gridview is set in the aspx, which is the ID of an asp:ObjectDataSource. A SelectMethod is...
2
by: shrikanthn | last post by:
Hi All, i am adding some data into GridView (adding 4 to 5 rows) at runtime in asp.net page using c#. but getting outofbond error.
1
by: siri11 | last post by:
Hi everyone... I'm developing an application in asp.net with C#.net and Sqlserver as backend connecting to a local server.In one of the web forms the requirement is such that when I select an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.