|
Hi all,
I am trying to fill a GridView with data from a MySql Table.
The gridview is defined in the ASP-file. In the code behind the next code should fill the gridview with data via a Stored Procedure combined with an Array of Parameters.
Codebehind:
<br />
private void SetGridChooseServices()<br />
{<br />
<br />
MySqlParameter[] arrParameter0 = new MySqlParameter[0];<br />
String StoredProc = "GetServices";<br />
gridChooseServices = db.WerkGridViewBij(gridChooseServices, gridChooseServices.PageIndex, StoredProc, arrParameter0);<br />
PlaatsveldenInGridView();<br />
}<br />
Method WerkGridViewBij (means updateGridView):
<br />
public GridView WerkGridViewBij(GridView gv, Int32 paginaNummer, String DataSourceSelectCommand, MySqlParameter[] sqlParameters)<br />
{<br />
MySqlDataReader reader;<br />
<br />
try<br />
{<br />
MySqlCommand cmd = BaseDatabaseData(DataSourceSelectCommand, sqlParameters);<br />
cmd.Connection.Open();<br />
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);<br />
gv.DataSource = reader;<br />
if (paginaNummer > gv.PageCount) paginaNummer = 0;<br />
if (gv.AllowPaging)<br />
gv.PageIndex = paginaNummer;<br />
gv.DataBind();
reader.Close();<br />
}<br />
catch (Exception err)<br />
{<br />
gv.ToolTip = err.Message;<br />
}<br />
finally<br />
{<br />
if (gv.Rows.Count.Equals(0))<br />
gv.ToolTip = "Geen data gevonden!";<br />
}<br />
return gv;<br />
}<br />
Method BaseDatabaseData (used in WerkGridViewBij):
<br />
private static MySqlCommand BaseDatabaseData(String StoredProc, MySqlParameter[] arrParameters)<br />
{<br />
String connection = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;<br />
MySqlConnection con = new MySqlConnection(connection);<br />
<br />
MySqlCommand cmd = new MySqlCommand(StoredProc, con);<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.AddRange(arrParameters);<br />
<br />
if (cmd.Connection.State == ConnectionState.Open)<br />
cmd.Connection.Close();<br />
<br />
return cmd;<br />
}<br />
In the method WerkGridViewBij the result from the DB is no records strange enough, while in the database 14 rows are selected. Why do these rows not show up ?
-- modified at 5:12 Wednesday 22nd August, 2007
Error occurs when doing gv.DataBind();
The error says:
{"De gegevensbron biedt geen ondersteuning voor gegevenspaginering op de server."}
The DataSource does not support datapaging on the server.
|
|
|
|
|
The error is found.
Datareader does not support paging.
I Changed the WerkGridViewBij-method to:
<br />
public GridView WerkGridViewBij(GridView gv, Int32 paginaNummer, String DataSourceSelectCommand, MySqlParameter[] sqlParameters)<br />
{<br />
try<br />
{<br />
<br />
<br />
MySqlCommand cmd = BaseDatabaseData(DataSourceSelectCommand, sqlParameters);<br />
cmd.Connection.Open();<br />
<br />
if (gv.AllowPaging)
{<br />
DataSet dset = new DataSet("GeneralDataSet");<br />
DataTable tabel = new DataTable("GeneralTable");<br />
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);<br />
adapter.Fill(tabel);<br />
gv.DataSource = tabel;<br />
if (paginaNummer > gv.PageCount) paginaNummer = 0;<br />
<br />
if (gv.AllowPaging)<br />
gv.PageIndex = paginaNummer;<br />
gv.DataBind();<br />
}<br />
else<br />
{<br />
MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);<br />
if (reader.HasRows)<br />
{<br />
gv.DataSource = reader;<br />
gv.DataBind();<br />
}<br />
reader.Close();<br />
}<br />
}<br />
catch (Exception err)<br />
{<br />
gv.ToolTip = err.Message;<br />
}<br />
finally<br />
{<br />
if (gv.Rows.Count.Equals(0) && gv.ToolTip.Equals(String.Empty))<br />
gv.ToolTip = "Geen data gevonden!";<br />
}<br />
return gv;<br />
}<br />
problem is solved
|
|
|
|
|
Hi,
I have a login control in my ASp.NET application. I use 'Users' table in SQL Server 2005 to authenticate the login. If the username & password are correct, I want to display the username in the loginview control. How can I do that?
|
|
|
|
|
put in a login view and put the login name in it .
if you want to display a message before the username use the format string in the properties window just don't remove the {0} at the end.
BiG RaLpH
|
|
|
|
|
can u pls put down a sample code here?
thanks in advance.....
|
|
|
|
|
first did you try to login successfully if not I will tell you what to do
BiG RaLpH
|
|
|
|
|
Yeah! Please Tell me from scratch how to do it.
I tried to use Login1_Authenticated() method to manually check the username & password but it didn't work.
Please tell me how to do the login & Display the username in the login view control.
Also How to handle LoggedInTeTemplate & AnnonymousTemplate...
Thanks
|
|
|
|
|
How to use flash and integrate it into ur website
www.2advanced.com
This website rocks
|
|
|
|
|
You can start by creating a flash movie.
For integrating into website, just use the object tag.
Point to note: Not all websites that use flash are "Wow". A badly designed flash interface can be irritating, difficult to maintain and may turn away users. Also its client-heavy.
Ajax should suffice unless you're creating a website for a las vegas condo.
SG
|
|
|
|
|
Hi,
I have a textbox that accepts numbers. I need to extract just the numbers in the orders as what they were entered, irrespective of what other text is entered.
I have the following:
Dim r As New Regex("^\d+$")
Dim matches As MatchCollection = r.Matches(strNum)
Response.Write("matches.Count = " & matches.Count)
When I enter "123-456", matches.Count is 0, but when I add "123" then the count is 1. How do I modify the regular expression so that it extracts the numbers, if "123-456" or "123/456" is entered then the end result must be "123456".
Please can someone help?
Regards,
.NET Enthusiast
|
|
|
|
|
write your own code, like
Protected Function SelectNumbers(ByVal alphaText As String) As String<br />
Dim num As String = ""<br />
Dim c As Char<br />
For i As Short = 0 To alphaText.Length - 1<br />
c = alphaText.Chars(i)<br />
If Char.IsDigit(c) Then<br />
num &= c<br />
End If<br />
Next<br />
Return num<br />
End Function
|
|
|
|
|
hi ..
i want to know how to access database and insert row in datagrid using javascipt.
this is my existing code
<columns>
<asp:templatecolumn>
<headerstyle width="10%">
<itemstyle font-underline="True" horizontalalign="Center" width="10%">
<itemtemplate>
<asp:hyperlink id="Hyperlink1" cssclass="bluelink" runat="server" navigateurl="<%# "../CareHistory/CareEpisodeDetails.aspx?CareId="+DataBinder.Eval(Container.DataItem,"CareId").ToString() %>" width="16%">
View
<asp:boundcolumn datafield="CareCategoryName" headertext="Care Group">
<headerstyle horizontalalign="Center" width="25%">
<asp:boundcolumn datafield="CareStartDate" headertext="Date From" dataformatstring="{0:dd/MM/yyyy}">
<headerstyle horizontalalign="Center" width="10%">
asp:BoundColumn DataField="CareDateTo" HeaderText="Date To" DataFormatString="{0:dd/MM/yyyy}">
<headerstyle horizontalalign="Center" width="10%">
asp:BoundColumn DataField="ReasonForChange" HeaderText="Reason For Change">
<headerstyle horizontalalign="Center" width="15%">
asp:BoundColumn DataField="FundingAuthority" HeaderText="Funding Authority">
<headerstyle horizontalalign="Center" width="15%">
asp:TemplateColumn HeaderText="Risk at Home">
<headerstyle horizontalalign="Center" width="15%" verticalalign="Middle">
<itemstyle horizontalalign="Center" verticalalign="Middle">
<itemtemplate>
<asp:label id="lblRiskAtHome" runat="server" width="125px" text="<%# DataBinder.Eval(Container.DataItem,"HomeVisitingSafetyIssues") %>">
i need existing from to javascript like below
var grid = new AW.UI.Grid;
grid.setId("myGrid");
grid.setHeaderText("header");
grid.setCellText(function(col, row){return col + "-" + row});
grid.setColumnCount(10);
grid.setRowCount(1000);
grid.refresh();
how to get that row please help me
thank u
nantha
|
|
|
|
|
It's not a datagrid, it's a table on the client side. You need to add rows to the client side table. A repeater is probably better for you to control how things are laid out for the javascript.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi..Christian Graus
thank u soo much i will try that . thank u once again..
reg
nanth
|
|
|
|
|
Hi..
Friends.
I'm getting this error while changig in 'httpHandler' section in web.config
by following code..
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
HttpHandlersSection sec = (HttpHandlersSection) objConfig.GetSection("system.web/httpHandlers");
sec.Handlers.RemoveAt(0);
HttpModulesSection sec2 = (HttpModulesSection)objConfig.GetSection("system.web/httpModules");
sec2.Modules.RemoveAt(0);
objConfig.Save(ConfigurationSaveMode.Full);
When, I m executing this code, I m getting this types of error message,
Access to the path 'c:\inetpub\wwwroot\FinalUploadProgress\web.config' is denied.
Please help me ASAP
Thanks in Advance..
Regards,
Abhi
|
|
|
|
|
check the authorization of ASP.NET and NETWORKSERVICE users. i got this error 6 days ago.
|
|
|
|
|
This code block is run on my developer pc. but i upload files to server then
I get an error "Object reference not set to an instance of an object"
on "dr.close"
whats wrong with this code?
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim conn As New System.Data.OleDb.OleDbConnection(MyConstants.sqlConnString)<br />
Dim cmd As New System.Data.OleDb.OleDbCommand("", conn)<br />
Dim dr As System.Data.OleDb.OleDbDataReader<br />
Dim msG As String = ""<br />
Try<br />
conn.Open()<br />
cmd.CommandText = "SELECT * FROM MD_USERS WHERE U_USERNAME='" & Login1.UserName & "' AND U_PASSWORD='" & Login1.Password & "' "<br />
dr = cmd.ExecuteReader<br />
If dr.Read Then<br />
Dim mu As New MyUser<br />
mu._ID = dr.Item("U_ID")<br />
mu._Name = dr.Item("U_CLASS") & " " & Myuser.SayDignity(dr.Item("U_DIGNITY")) & " " & dr.Item("U_NAME") & " " & dr.Item("U_SURNAME")<br />
mu._CATEGORY = dr.Item("U_CATEGORY")<br />
mu._AUTHORITY = dr.Item("U_AUTHORITY")<br />
Session("MYUSER") = mu<br />
e.Authenticated = True<br />
End If<br />
Catch ex As Exception<br />
msG = ex.Message<br />
Finally<br />
dr.Close()<br />
conn.Close()<br />
End Try<br />
If Not msj = "" Then<br />
Session("msG") = msG<br />
Response.Redirect("Messages.aspx")<br />
End If<br />
End Sub
also What do u offer to improve this code?
|
|
|
|
|
greekius@hotmail.com wrote: dr.Close()
#1. You should check like ~
If dr IsNot Nothing Then If Not dr.IsClosed Then dr.Close()
#2. You should check whether dr is nothing or not before "dr.Read" too.
Thanks and Regards,
Michael Sync ( Blog: http://michaelsync.net)
If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you.
|
|
|
|
|
Declare this statement : Dim dr As System.Data.OleDb.OleDbDataReader
above of the function
Dim dr As System.Data.OleDb.OleDbDataReader
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
{
................
..................
..............
}
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
May be in this case you won't be getting dr object. Some exception happened before you issue ExecuteReader() , that will force to execute finally block. In finally block you are trying to close datareader that is not yet instantiated. To avoid this, make sure dr is not null before you try to close it.
greekius@hotmail.com wrote: also What do u offer to improve this code?
You need to look for some good articles that explains SQL Injection attacks. Your code is too close to that. I feel better approach would be using parameterized queries or Stored Procedures.
|
|
|
|
|
Parwej Ahamad wrote: Dim dr As System.Data.OleDb.OleDbDataReader
This won't solve prob I think. dr is not instantiating
|
|
|
|
|
I know but Execute reader return the reader object.
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
Parwej Ahamad wrote: know but Execute reader return the reader object.
Yes but what will happen if exception occurred before ExecuteReader() ? Then dr will not be instantiated
|
|
|
|
|
I agree, But i m post here as per the first post. if you want handle that kind of exception then we need to check Reader is null or not.
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
i think there is no prb wit "dr". 'cos this code works on my local pc. i guess the problem is about server. but what is that:s
|
|
|
|