Thursday, March 29, 2012
Pass NULL To Stored Procedure
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
ALTER PROCEDURE dbo.Purchase
@dotnet.itags.org.UserID int,
@dotnet.itags.org.Total decimal,
@dotnet.itags.org.Address varchar(250) = NULL,
@dotnet.itags.org.Country varchar(50) = NULL
AS
INSERT INTO Order (UserID, Address, Country, Total) VALUES (@dotnet.itags.org.UserID,
@dotnet.itags.org.Address, @dotnet.itags.org.Country, @dotnet.itags.org.Total)
I am invoking the above SP with this code in a class file:
Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@dotnet.itags.org.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@dotnet.itags.org.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@dotnet.itags.org.Country", SqlDbType.VarChar, 50).Value =
Country
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
Using vbc, I compiled the above into a DLL named Cart.dll.
This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):
Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart
If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If
If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If
boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub<rn5a@.rediffmail.com> wrote in message
news:1160169983.937789.306620@.k70g2000cwa.googlegroups.com...
> How do I pass a NULL value to a field while inserting records in a SQL
> Server 2005 DB table using a stored procedure? I tried the following
> but it inserts an empty string & not a NULL value:
.Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value = DbNull.Value
Plus what Mark mention
I think you can set your instance to Nothing
like:
address = nothing;
but if you your object is value type, you have to use the way Mark Mentioned
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"rn5a@.rediffmail.com" wrote:
> How do I pass a NULL value to a field while inserting records in a SQL
> Server 2005 DB table using a stored procedure? I tried the following
> but it inserts an empty string & not a NULL value:
> ALTER PROCEDURE dbo.Purchase
> @.UserID int,
> @.Total decimal,
> @.Address varchar(250) = NULL,
> @.Country varchar(50) = NULL
> AS
> INSERT INTO Order (UserID, Address, Country, Total) VALUES (@.UserID,
> @.Address, @.Country, @.Total)
> I am invoking the above SP with this code in a class file:
> Public Class Cart
> Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
> Double, ByVal Address As String, ByVal Country As String)
> Dim sqlConn As SqlConnection
> Dim sqlCmd As SqlCommand
> sqlConn = New SqlConnection("....")
> sqlCmd = New SqlCommand("Purchase", sqlConn)
> sqlCmd.CommandType = CommandType.StoredProcedure
> With sqlCmd
> .Parameters.Add("@.UserID", SqlDbType.Int).Value = UserID
> .Parameters.Add("@.Total", SqlDbType.Decimal).Value = Total
> .Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value =
> Address
> .Parameters.Add("@.Country", SqlDbType.VarChar, 50).Value =
> Country
> End With
> sqlConn.Open()
> sqlCmd.ExecuteNonQuery()
> sqlConn.Close()
> End Sub
> End Class
> Using vbc, I compiled the above into a DLL named Cart.dll.
> This is the ASPX code (if no values are supplied for the variables
> 'strAddress' & 'strCountry', those records should be inserted as NULLs
> in the DB table):
> Sub Submit_Click(....)
> Dim boCart As Cart
> boCart = New Cart
> If (strAddress = "") Then
> strAddress = DBNull.Value.ToString
> End If
> If (strCountry = "") Then
> strCountry = DBNull.Value.ToString
> End If
> boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
> End Sub
>
Pass NULL To Stored Procedure
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
ALTER PROCEDURE dbo.Purchase
@dotnet.itags.org.UserID int,
@dotnet.itags.org.Total decimal,
@dotnet.itags.org.Address varchar(250) = NULL,
@dotnet.itags.org.Country varchar(50) = NULL
AS
INSERT INTO Order (UserID, Address, Country, Total) VALUES (@dotnet.itags.org.UserID,
@dotnet.itags.org.Address, @dotnet.itags.org.Country, @dotnet.itags.org.Total)
I am invoking the above SP with this code in a class file:
Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
With sqlCmd
.Parameters.Add("@dotnet.itags.org.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@dotnet.itags.org.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@dotnet.itags.org.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@dotnet.itags.org.Country", SqlDbType.VarChar, 50).Value =
Country
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
Using vbc, I compiled the above into a DLL named Cart.dll.
This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):
Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart
If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If
If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If
boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub<rn5a@.rediffmail.comwrote in message
news:1160169983.937789.306620@.k70g2000cwa.googlegr oups.com...
Quote:
Originally Posted by
How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
..Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value = DbNull.Value
Plus what Mark mention
I think you can set your instance to Nothing
like:
address = nothing;
but if you your object is value type, you have to use the way Mark Mentioned
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"rn5a@.rediffmail.com" wrote:
Quote:
Originally Posted by
How do I pass a NULL value to a field while inserting records in a SQL
Server 2005 DB table using a stored procedure? I tried the following
but it inserts an empty string & not a NULL value:
>
ALTER PROCEDURE dbo.Purchase
@.UserID int,
@.Total decimal,
@.Address varchar(250) = NULL,
@.Country varchar(50) = NULL
AS
>
INSERT INTO Order (UserID, Address, Country, Total) VALUES (@.UserID,
@.Address, @.Country, @.Total)
>
I am invoking the above SP with this code in a class file:
>
Public Class Cart
Public Sub PlaceOrder(ByVal UserID As Integer, ByVal Total As
Double, ByVal Address As String, ByVal Country As String)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
>
sqlConn = New SqlConnection("....")
sqlCmd = New SqlCommand("Purchase", sqlConn)
sqlCmd.CommandType = CommandType.StoredProcedure
>
With sqlCmd
.Parameters.Add("@.UserID", SqlDbType.Int).Value = UserID
.Parameters.Add("@.Total", SqlDbType.Decimal).Value = Total
.Parameters.Add("@.Address", SqlDbType.VarChar, 250).Value =
Address
.Parameters.Add("@.Country", SqlDbType.VarChar, 50).Value =
Country
End With
>
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
>
Using vbc, I compiled the above into a DLL named Cart.dll.
>
This is the ASPX code (if no values are supplied for the variables
'strAddress' & 'strCountry', those records should be inserted as NULLs
in the DB table):
>
Sub Submit_Click(....)
Dim boCart As Cart
boCart = New Cart
>
If (strAddress = "") Then
strAddress = DBNull.Value.ToString
End If
>
If (strCountry = "") Then
strCountry = DBNull.Value.ToString
End If
>
boCart.PlaceOrder(iUserID, dblTotal, strAddress, strCountry)
End Sub
>
>
Monday, March 26, 2012
pass table back to webpage
I have a page with a table. I built a custom class that creates a
System.Web.UI.WebControls table object and return it to the webpage as a
property. But its not reading the table correctly. It doesnt see the
tablerows and tablecell objects.
First, I'm not sure why its not reading the table properly?
Second, I wonder if there's a better way to do this? Maybe a custom control?
I haven't really gotten into these yet. My table only contains some
hyperlinks to open other pages. so no other server-side processing after
this.What do you mean by "Not reading the table properly". If collections are
empty could it be you forgotten to add them asd they are created to your
table ?
Patrice
--
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> I'm wondering what the best way to do the following:
> I have a page with a table. I built a custom class that creates a
> System.Web.UI.WebControls table object and return it to the webpage as a
> property. But its not reading the table correctly. It doesnt see the
> tablerows and tablecell objects.
> First, I'm not sure why its not reading the table properly?
> Second, I wonder if there's a better way to do this? Maybe a custom
control?
> I haven't really gotten into these yet. My table only contains some
> hyperlinks to open other pages. so no other server-side processing after
> this.
The table in the webpage is set to the returned table from the custom class
function. I know that there's data rows and cells in it.
on webpage:
objBusLog.FillTable(); //this is call to define the table
TblRpt = objBusLog.TblReports; //This sets table web control to actual
table being set in custom class.
??
"Patrice" wrote:
> What do you mean by "Not reading the table properly". If collections are
> empty could it be you forgotten to add them asd they are created to your
> table ?
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > I'm wondering what the best way to do the following:
> > I have a page with a table. I built a custom class that creates a
> > System.Web.UI.WebControls table object and return it to the webpage as a
> > property. But its not reading the table correctly. It doesnt see the
> > tablerows and tablecell objects.
> > First, I'm not sure why its not reading the table properly?
> > Second, I wonder if there's a better way to do this? Maybe a custom
> control?
> > I haven't really gotten into these yet. My table only contains some
> > hyperlinks to open other pages. so no other server-side processing after
> > this.
>
What I don't understand for now is the result you have.
Do you mean you have no HTML at all rendered for this table ?
If yes, it's likely this control is not part of the page.
Do you mean you have rows missing ? What if you show the rows count to see
if it's what you expect ?
If not it's likely rows are not added in the collection...
Etc...
Some basic code would be :
System.Web.UI.WebControls.Table TestFunction()
{
System.Web.UI.WebControls.Table t=new System.Web.UI.WebControls.Table();
System.Web.UI.WebControls.TableRow r=new
System.Web.UI.WebControls.TableRow();
System.Web.UI.WebControls.TableCell c=new
System.Web.UI.WebControls.TableCell();
r.Cells.Add(c);
t.Rows.Add(r);
return t;
}
void Page_Load(Object sender,System.EventArgs e)
{
Form1.Controls.Add(TestFunction());
}
(use "view source" in your browser to see that it renders an empty HTML
table).
Hope it helps...
Patrice
--
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> The table in the webpage is set to the returned table from the custom
class
> function. I know that there's data rows and cells in it.
> on webpage:
> objBusLog.FillTable(); //this is call to define the table
> TblRpt = objBusLog.TblReports; //This sets table web control to actual
> table being set in custom class.
> ??
> "Patrice" wrote:
> > What do you mean by "Not reading the table properly". If collections are
> > empty could it be you forgotten to add them asd they are created to your
> > table ?
> > Patrice
> > --
> > "klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
> > news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > > I'm wondering what the best way to do the following:
> > > I have a page with a table. I built a custom class that creates a
> > > System.Web.UI.WebControls table object and return it to the webpage as
a
> > > property. But its not reading the table correctly. It doesnt see the
> > > tablerows and tablecell objects.
> > > First, I'm not sure why its not reading the table properly?
> > > Second, I wonder if there's a better way to do this? Maybe a custom
> > control?
> > > I haven't really gotten into these yet. My table only contains some
> > > hyperlinks to open other pages. so no other server-side processing
after
> > > this.
Yes, the table is indeed a server side control. If I run the code directly in
the page_load, to build the table, all is good, like the way, your test
function is setup..
But in my case, I create a new class that creates the table. Then I get a
property as follows:
public System.Web.UI.WebControls.Table TblReports
{
get
{
return m_objTblRpts;
}
}}
When I print the number of rows in the web page, it comes back as 2. But it
doesnt actually print the rows of the table. It only prints the following:
<table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT: 24px;
POSITION: absolute; TOP: 352px"
Can I not return a table in a class property??
"Patrice" wrote:
> What I don't understand for now is the result you have.
> Do you mean you have no HTML at all rendered for this table ?
> If yes, it's likely this control is not part of the page.
> Do you mean you have rows missing ? What if you show the rows count to see
> if it's what you expect ?
> If not it's likely rows are not added in the collection...
> Etc...
> Some basic code would be :
> System.Web.UI.WebControls.Table TestFunction()
> {
> System.Web.UI.WebControls.Table t=new System.Web.UI.WebControls.Table();
> System.Web.UI.WebControls.TableRow r=new
> System.Web.UI.WebControls.TableRow();
> System.Web.UI.WebControls.TableCell c=new
> System.Web.UI.WebControls.TableCell();
> r.Cells.Add(c);
> t.Rows.Add(r);
> return t;
> }
> void Page_Load(Object sender,System.EventArgs e)
> {
> Form1.Controls.Add(TestFunction());
> }
> (use "view source" in your browser to see that it renders an empty HTML
> table).
> Hope it helps...
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> > The table in the webpage is set to the returned table from the custom
> class
> > function. I know that there's data rows and cells in it.
> > on webpage:
> > objBusLog.FillTable(); //this is call to define the table
> > TblRpt = objBusLog.TblReports; //This sets table web control to actual
> > table being set in custom class.
> > ??
> > "Patrice" wrote:
> > > What do you mean by "Not reading the table properly". If collections are
> > > empty could it be you forgotten to add them asd they are created to your
> > > table ?
> > > > Patrice
> > > > --
> > > > "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> > > news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > > > I'm wondering what the best way to do the following:
> > > > I have a page with a table. I built a custom class that creates a
> > > > System.Web.UI.WebControls table object and return it to the webpage as
> a
> > > > property. But its not reading the table correctly. It doesnt see the
> > > > tablerows and tablecell objects.
> > > > First, I'm not sure why its not reading the table properly?
> > > > Second, I wonder if there's a better way to do this? Maybe a custom
> > > control?
> > > > I haven't really gotten into these yet. My table only contains some
> > > > hyperlinks to open other pages. so no other server-side processing
> after
> > > > this.
> > > >
It looks like to me you are assigning TblRpts a *new* object and that you
would expect this new object to be rendered.
Actually behind the scene this object is registered in the "Controls"
collection before your code runs. As a result, assigning a *new* object to
this object variable won't have any effect (keep in mind that objects
variables are nothing else than "pointers").
I see basically two solutions :
- add the *new* control to the controls collection (and you don't need to
have the TblRpts controls in your page)
- pass TblRpts to your function so that you can add rows to the existing
control rather than creating a new one
Hope it helps...
Patrice
--
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:E71CE228-7F0F-4182-8BDE-B43EA076A25C@.microsoft.com...
> Yes, the table is indeed a server side control. If I run the code directly
in
> the page_load, to build the table, all is good, like the way, your test
> function is setup..
> But in my case, I create a new class that creates the table. Then I get a
> property as follows:
> public System.Web.UI.WebControls.Table TblReports
> {
> get
> {
> return m_objTblRpts;
> }
> } }
> When I print the number of rows in the web page, it comes back as 2. But
it
> doesnt actually print the rows of the table. It only prints the following:
> <table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT:
24px;
> POSITION: absolute; TOP: 352px">
> Can I not return a table in a class property??
>
> "Patrice" wrote:
> > What I don't understand for now is the result you have.
> > Do you mean you have no HTML at all rendered for this table ?
> > If yes, it's likely this control is not part of the page.
> > Do you mean you have rows missing ? What if you show the rows count to
see
> > if it's what you expect ?
> > If not it's likely rows are not added in the collection...
> > Etc...
> > Some basic code would be :
> > System.Web.UI.WebControls.Table TestFunction()
> > {
> > System.Web.UI.WebControls.Table t=new
System.Web.UI.WebControls.Table();
> > System.Web.UI.WebControls.TableRow r=new
> > System.Web.UI.WebControls.TableRow();
> > System.Web.UI.WebControls.TableCell c=new
> > System.Web.UI.WebControls.TableCell();
> > r.Cells.Add(c);
> > t.Rows.Add(r);
> > return t;
> > }
> > void Page_Load(Object sender,System.EventArgs e)
> > {
> > Form1.Controls.Add(TestFunction());
> > }
> > (use "view source" in your browser to see that it renders an empty HTML
> > table).
> > Hope it helps...
> > Patrice
> > --
> > "klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
> > news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> > > The table in the webpage is set to the returned table from the custom
> > class
> > > function. I know that there's data rows and cells in it.
> > > on webpage:
> > > objBusLog.FillTable(); //this is call to define the table
> > > TblRpt = objBusLog.TblReports; //This sets table web control to
actual
> > > table being set in custom class.
> > > > ??
> > > > "Patrice" wrote:
> > > > > What do you mean by "Not reading the table properly". If collections
are
> > > > empty could it be you forgotten to add them asd they are created to
your
> > > > table ?
> > > > > > Patrice
> > > > > > --
> > > > > > "klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
> > > > news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > > > > I'm wondering what the best way to do the following:
> > > > > I have a page with a table. I built a custom class that creates a
> > > > > System.Web.UI.WebControls table object and return it to the
webpage as
> > a
> > > > > property. But its not reading the table correctly. It doesnt see
the
> > > > > tablerows and tablecell objects.
> > > > > First, I'm not sure why its not reading the table properly?
> > > > > Second, I wonder if there's a better way to do this? Maybe a
custom
> > > > control?
> > > > > I haven't really gotten into these yet. My table only contains
some
> > > > > hyperlinks to open other pages. so no other server-side processing
> > after
> > > > > this.
> > > > > >
Thanks. That was it!
Appreciate it.
That leads back to the first question:
I'm trying to do this using a fairly good 'object-oriented' methodology. So
creating a new class to build a table, and return the table.. Is that the
best method?
"Patrice" wrote:
> It looks like to me you are assigning TblRpts a *new* object and that you
> would expect this new object to be rendered.
> Actually behind the scene this object is registered in the "Controls"
> collection before your code runs. As a result, assigning a *new* object to
> this object variable won't have any effect (keep in mind that objects
> variables are nothing else than "pointers").
> I see basically two solutions :
> - add the *new* control to the controls collection (and you don't need to
> have the TblRpts controls in your page)
> - pass TblRpts to your function so that you can add rows to the existing
> control rather than creating a new one
> Hope it helps...
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:E71CE228-7F0F-4182-8BDE-B43EA076A25C@.microsoft.com...
> > Yes, the table is indeed a server side control. If I run the code directly
> in
> > the page_load, to build the table, all is good, like the way, your test
> > function is setup..
> > But in my case, I create a new class that creates the table. Then I get a
> > property as follows:
> > public System.Web.UI.WebControls.Table TblReports
> > {
> > get
> > {
> > return m_objTblRpts;
> > }
> > } }
> > When I print the number of rows in the web page, it comes back as 2. But
> it
> > doesnt actually print the rows of the table. It only prints the following:
> > <table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT:
> 24px;
> > POSITION: absolute; TOP: 352px">
> > Can I not return a table in a class property??
> > "Patrice" wrote:
> > > What I don't understand for now is the result you have.
> > > > Do you mean you have no HTML at all rendered for this table ?
> > > If yes, it's likely this control is not part of the page.
> > > > Do you mean you have rows missing ? What if you show the rows count to
> see
> > > if it's what you expect ?
> > > If not it's likely rows are not added in the collection...
> > > > Etc...
> > > > Some basic code would be :
> > > > System.Web.UI.WebControls.Table TestFunction()
> > > {
> > > System.Web.UI.WebControls.Table t=new
> System.Web.UI.WebControls.Table();
> > > System.Web.UI.WebControls.TableRow r=new
> > > System.Web.UI.WebControls.TableRow();
> > > System.Web.UI.WebControls.TableCell c=new
> > > System.Web.UI.WebControls.TableCell();
> > > r.Cells.Add(c);
> > > t.Rows.Add(r);
> > > return t;
> > > }
> > > void Page_Load(Object sender,System.EventArgs e)
> > > {
> > > Form1.Controls.Add(TestFunction());
> > > }
> > > > (use "view source" in your browser to see that it renders an empty HTML
> > > table).
> > > > Hope it helps...
> > > > Patrice
> > > > --
> > > > "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> > > news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> > > > The table in the webpage is set to the returned table from the custom
> > > class
> > > > function. I know that there's data rows and cells in it.
> > > > on webpage:
> > > > objBusLog.FillTable(); //this is call to define the table
> > > > TblRpt = objBusLog.TblReports; //This sets table web control to
> actual
> > > > table being set in custom class.
> > > > > > ??
> > > > > > "Patrice" wrote:
> > > > > > > What do you mean by "Not reading the table properly". If collections
> are
> > > > > empty could it be you forgotten to add them asd they are created to
> your
> > > > > table ?
> > > > > > > > Patrice
> > > > > > > > --
> > > > > > > > "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> > > > > news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > > > > > I'm wondering what the best way to do the following:
> > > > > > I have a page with a table. I built a custom class that creates a
> > > > > > System.Web.UI.WebControls table object and return it to the
> webpage as
> > > a
> > > > > > property. But its not reading the table correctly. It doesnt see
> the
> > > > > > tablerows and tablecell objects.
> > > > > > First, I'm not sure why its not reading the table properly?
> > > > > > Second, I wonder if there's a better way to do this? Maybe a
> custom
> > > > > control?
> > > > > > I haven't really gotten into these yet. My table only contains
> some
> > > > > > hyperlinks to open other pages. so no other server-side processing
> > > after
> > > > > > this.
> > > > > > > > > > > > >
Depending on what it does you could create a control (in particular it
allows if applicable to provide some design time support).
You could also expose this a as "static" function depending on wether or not
it contains a state...
The key point is IMO to keep each part in its own layer and only using well
defined interactions with other parts, not doing things "OO" for its own
sake. As long as you do this, it will be easier to evolve each part
separately...
Patrice
--
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:F7D8AB59-FDC8-4BFB-8851-D22FD6EDBC03@.microsoft.com...
> Thanks. That was it!
> Appreciate it.
> That leads back to the first question:
> I'm trying to do this using a fairly good 'object-oriented' methodology.
So
> creating a new class to build a table, and return the table.. Is that the
> best method?
> "Patrice" wrote:
> > It looks like to me you are assigning TblRpts a *new* object and that
you
> > would expect this new object to be rendered.
> > Actually behind the scene this object is registered in the "Controls"
> > collection before your code runs. As a result, assigning a *new* object
to
> > this object variable won't have any effect (keep in mind that objects
> > variables are nothing else than "pointers").
> > I see basically two solutions :
> > - add the *new* control to the controls collection (and you don't need
to
> > have the TblRpts controls in your page)
> > - pass TblRpts to your function so that you can add rows to the existing
> > control rather than creating a new one
> > Hope it helps...
> > Patrice
> > --
> > "klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
> > news:E71CE228-7F0F-4182-8BDE-B43EA076A25C@.microsoft.com...
> > > Yes, the table is indeed a server side control. If I run the code
directly
> > in
> > > the page_load, to build the table, all is good, like the way, your
test
> > > function is setup..
> > > > But in my case, I create a new class that creates the table. Then I
get a
> > > property as follows:
> > > public System.Web.UI.WebControls.Table TblReports
> > > {
> > > get
> > > {
> > > return m_objTblRpts;
> > > }
> > > } }
> > > When I print the number of rows in the web page, it comes back as 2.
But
> > it
> > > doesnt actually print the rows of the table. It only prints the
following:
> > > <table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT:
> > 24px;
> > > POSITION: absolute; TOP: 352px">
> > > > Can I not return a table in a class property??
> > > > > "Patrice" wrote:
> > > > > What I don't understand for now is the result you have.
> > > > > > Do you mean you have no HTML at all rendered for this table ?
> > > > If yes, it's likely this control is not part of the page.
> > > > > > Do you mean you have rows missing ? What if you show the rows count
to
> > see
> > > > if it's what you expect ?
> > > > If not it's likely rows are not added in the collection...
> > > > > > Etc...
> > > > > > Some basic code would be :
> > > > > > System.Web.UI.WebControls.Table TestFunction()
> > > > {
> > > > System.Web.UI.WebControls.Table t=new
> > System.Web.UI.WebControls.Table();
> > > > System.Web.UI.WebControls.TableRow r=new
> > > > System.Web.UI.WebControls.TableRow();
> > > > System.Web.UI.WebControls.TableCell c=new
> > > > System.Web.UI.WebControls.TableCell();
> > > > r.Cells.Add(c);
> > > > t.Rows.Add(r);
> > > > return t;
> > > > }
> > > > void Page_Load(Object sender,System.EventArgs e)
> > > > {
> > > > Form1.Controls.Add(TestFunction());
> > > > }
> > > > > > (use "view source" in your browser to see that it renders an empty
HTML
> > > > table).
> > > > > > Hope it helps...
> > > > > > Patrice
> > > > > > --
> > > > > > "klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
> > > > news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> > > > > The table in the webpage is set to the returned table from the
custom
> > > > class
> > > > > function. I know that there's data rows and cells in it.
> > > > > on webpage:
> > > > > objBusLog.FillTable(); //this is call to define the table
> > > > > TblRpt = objBusLog.TblReports; //This sets table web control to
> > actual
> > > > > table being set in custom class.
> > > > > > > > ??
> > > > > > > > "Patrice" wrote:
> > > > > > > > > What do you mean by "Not reading the table properly". If
collections
> > are
> > > > > > empty could it be you forgotten to add them asd they are created
to
> > your
> > > > > > table ?
> > > > > > > > > > Patrice
> > > > > > > > > > --
> > > > > > > > > > "klynn" <klynn@.discussions.microsoft.com> a crit dans le
message de
> > > > > > news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> > > > > > > I'm wondering what the best way to do the following:
> > > > > > > I have a page with a table. I built a custom class that
creates a
> > > > > > > System.Web.UI.WebControls table object and return it to the
> > webpage as
> > > > a
> > > > > > > property. But its not reading the table correctly. It doesnt
see
> > the
> > > > > > > tablerows and tablecell objects.
> > > > > > > First, I'm not sure why its not reading the table properly?
> > > > > > > Second, I wonder if there's a better way to do this? Maybe a
> > custom
> > > > > > control?
> > > > > > > I haven't really gotten into these yet. My table only contains
> > some
> > > > > > > hyperlinks to open other pages. so no other server-side
processing
> > > > after
> > > > > > > this.
> > > > > > > > > > > > > > > > > >
pass table back to webpage
I have a page with a table. I built a custom class that creates a
System.Web.UI.WebControls table object and return it to the webpage as a
property. But its not reading the table correctly. It doesnt see the
tablerows and tablecell objects.
First, I'm not sure why its not reading the table properly?
Second, I wonder if there's a better way to do this? Maybe a custom control?
I haven't really gotten into these yet. My table only contains some
hyperlinks to open other pages. so no other server-side processing after
this.What do you mean by "Not reading the table properly". If collections are
empty could it be you forgotten to add them asd they are created to your
table ?
Patrice
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> I'm wondering what the best way to do the following:
> I have a page with a table. I built a custom class that creates a
> System.Web.UI.WebControls table object and return it to the webpage as a
> property. But its not reading the table correctly. It doesnt see the
> tablerows and tablecell objects.
> First, I'm not sure why its not reading the table properly?
> Second, I wonder if there's a better way to do this? Maybe a custom
control?
> I haven't really gotten into these yet. My table only contains some
> hyperlinks to open other pages. so no other server-side processing after
> this.
The table in the webpage is set to the returned table from the custom class
function. I know that there's data rows and cells in it.
on webpage:
objBusLog.FillTable(); //this is call to define the table
TblRpt = objBusLog.TblReports; //This sets table web control to actual
table being set in custom class.
'
"Patrice" wrote:
> What do you mean by "Not reading the table properly". If collections are
> empty could it be you forgotten to add them asd they are created to your
> table ?
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:77A30CE6-FBD4-4591-A6C6-9D3FB1015117@.microsoft.com...
> control?
>
>
What I don't understand for now is the result you have.
Do you mean you have no HTML at all rendered for this table ?
If yes, it's likely this control is not part of the page.
Do you mean you have rows missing ? What if you show the rows count to see
if it's what you expect ?
If not it's likely rows are not added in the collection...
Etc...
Some basic code would be :
System.Web.UI.WebControls.Table TestFunction()
{
System.Web.UI.WebControls.Table t=new System.Web.UI.WebControls.Table();
System.Web.UI.WebControls.TableRow r=new
System.Web.UI.WebControls.TableRow();
System.Web.UI.WebControls.TableCell c=new
System.Web.UI.WebControls.TableCell();
r.Cells.Add(c);
t.Rows.Add(r);
return t;
}
void Page_Load(Object sender,System.EventArgs e)
{
Form1.Controls.Add(TestFunction());
}
(use "view source" in your browser to see that it renders an empty HTML
table).
Hope it helps...
Patrice
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> The table in the webpage is set to the returned table from the custom
class
> function. I know that there's data rows and cells in it.
> on webpage:
> objBusLog.FillTable(); //this is call to define the table
> TblRpt = objBusLog.TblReports; //This sets table web control to actual
> table being set in custom class.
> '
> "Patrice" wrote:
>
a
after
Yes, the table is indeed a server side control. If I run the code directly i
n
the page_load, to build the table, all is good, like the way, your test
function is setup..
But in my case, I create a new class that creates the table. Then I get a
property as follows:
public System.Web.UI.WebControls.Table TblReports
{
get
{
return m_objTblRpts;
}
} }
When I print the number of rows in the web page, it comes back as 2. But it
doesnt actually print the rows of the table. It only prints the following:
<table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT: 24px;
POSITION: absolute; TOP: 352px">
Can I not return a table in a class property'
"Patrice" wrote:
> What I don't understand for now is the result you have.
> Do you mean you have no HTML at all rendered for this table ?
> If yes, it's likely this control is not part of the page.
> Do you mean you have rows missing ? What if you show the rows count to see
> if it's what you expect ?
> If not it's likely rows are not added in the collection...
> Etc...
> Some basic code would be :
> System.Web.UI.WebControls.Table TestFunction()
> {
> System.Web.UI.WebControls.Table t=new System.Web.UI.WebControls.Table();
> System.Web.UI.WebControls.TableRow r=new
> System.Web.UI.WebControls.TableRow();
> System.Web.UI.WebControls.TableCell c=new
> System.Web.UI.WebControls.TableCell();
> r.Cells.Add(c);
> t.Rows.Add(r);
> return t;
> }
> void Page_Load(Object sender,System.EventArgs e)
> {
> Form1.Controls.Add(TestFunction());
> }
> (use "view source" in your browser to see that it renders an empty HTML
> table).
> Hope it helps...
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:E7684476-F77A-4077-9DEF-71C88810280C@.microsoft.com...
> class
> a
> after
>
>
It looks like to me you are assigning TblRpts a *new* object and that you
would expect this new object to be rendered.
Actually behind the scene this object is registered in the "Controls"
collection before your code runs. As a result, assigning a *new* object to
this object variable won't have any effect (keep in mind that objects
variables are nothing else than "pointers").
I see basically two solutions :
- add the *new* control to the controls collection (and you don't need to
have the TblRpts controls in your page)
- pass TblRpts to your function so that you can add rows to the existing
control rather than creating a new one
Hope it helps...
Patrice
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:E71CE228-7F0F-4182-8BDE-B43EA076A25C@.microsoft.com...
> Yes, the table is indeed a server side control. If I run the code directly
in
> the page_load, to build the table, all is good, like the way, your test
> function is setup..
> But in my case, I create a new class that creates the table. Then I get a
> property as follows:
> public System.Web.UI.WebControls.Table TblReports
> {
> get
> {
> return m_objTblRpts;
> }
> } }
> When I print the number of rows in the web page, it comes back as 2. But
it
> doesnt actually print the rows of the table. It only prints the following:
> <table id="TblRpts" border="0" style="width:928px;Z-INDEX: 108; LEFT:
24px;
> POSITION: absolute; TOP: 352px">
> Can I not return a table in a class property'
>
> "Patrice" wrote:
>
see
System.Web.UI.WebControls.Table();
actual
are
your
webpage as
the
custom
some
Thanks. That was it!
Appreciate it.
That leads back to the first question:
I'm trying to do this using a fairly good 'object-oriented' methodology. So
creating a new class to build a table, and return the table.. Is that the
best method?
"Patrice" wrote:
> It looks like to me you are assigning TblRpts a *new* object and that you
> would expect this new object to be rendered.
> Actually behind the scene this object is registered in the "Controls"
> collection before your code runs. As a result, assigning a *new* object to
> this object variable won't have any effect (keep in mind that objects
> variables are nothing else than "pointers").
> I see basically two solutions :
> - add the *new* control to the controls collection (and you don't need to
> have the TblRpts controls in your page)
> - pass TblRpts to your function so that you can add rows to the existing
> control rather than creating a new one
> Hope it helps...
> Patrice
> --
> "klynn" <klynn@.discussions.microsoft.com> a écrit dans le message de
> news:E71CE228-7F0F-4182-8BDE-B43EA076A25C@.microsoft.com...
> in
> it
> 24px;
> see
> System.Web.UI.WebControls.Table();
> actual
> are
> your
> webpage as
> the
> custom
> some
>
>
Depending on what it does you could create a control (in particular it
allows if applicable to provide some design time support).
You could also expose this a as "static" function depending on wether or not
it contains a state...
The key point is IMO to keep each part in its own layer and only using well
defined interactions with other parts, not doing things "OO" for its own
sake. As long as you do this, it will be easier to evolve each part
separately...
Patrice
"klynn" <klynn@.discussions.microsoft.com> a crit dans le message de
news:F7D8AB59-FDC8-4BFB-8851-D22FD6EDBC03@.microsoft.com...
> Thanks. That was it!
> Appreciate it.
> That leads back to the first question:
> I'm trying to do this using a fairly good 'object-oriented' methodology.
So
> creating a new class to build a table, and return the table.. Is that the
> best method?
> "Patrice" wrote:
>
you
to
to
directly
test
get a
But
following:
to
HTML
custom
collections
to
message de
creates a
see
processing
Pass UserID instead of Username to other pages after logged on, ASP.NET 2.0
I have my own user table with definition like
UserID int not null primary key,
Username varchar(50) not null,
Password varchar(50) not null,
Firstname varchar(50) not null,
Lastname varchar(50) not null,
Email varchar(50) not null,
....
I create my own Membership provider to inherit SqlMembershipProvider
public class MyMembershipProvider :
System.Web.Security.SqlMembershipProvider {
public MyMembershipProvider() {
}
public override bool ValidateUser(string username, string password) {
// query my DB to verify user
MyUser mu = new MyUser();
return mu.VerifyUser(username, password);
}
}
In Asp.Net 1.1, we can use
FormsAuthentication.RedirectFromLoginPage(UserID.ToString(), false); to save
UserID (which is whatever I return from my own function, including UserID
from User table). Later on, we just call User.Identity.Name to retrieve the
UserID and it could be used as I like.
But in ASP.NET 2.0, I just need to add
<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="MyMembershipProvider"/>
</providers>
</membership>
to my web.config file, it will handle authentication autimatically. In this
case how can I pass UserID instead of username to other pages?
Thanks
HardyHardy,
Why pass it around? Why not set a session variable with the information
you need?
- Nicholas Paldino [.NET/C# MVP]
- mvp@.spam.guard.caspershouse.com
"Hardy Wang" <hardywang@.hotmail.com> wrote in message
news:umAPpLP%23FHA.1988@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have my own user table with definition like
> UserID int not null primary key,
> Username varchar(50) not null,
> Password varchar(50) not null,
> Firstname varchar(50) not null,
> Lastname varchar(50) not null,
> Email varchar(50) not null,
> ....
> I create my own Membership provider to inherit SqlMembershipProvider
> public class MyMembershipProvider :
> System.Web.Security.SqlMembershipProvider {
> public MyMembershipProvider() {
> }
> public override bool ValidateUser(string username, string password) {
> // query my DB to verify user
> MyUser mu = new MyUser();
> return mu.VerifyUser(username, password);
> }
> }
> In Asp.Net 1.1, we can use
> FormsAuthentication.RedirectFromLoginPage(UserID.ToString(), false); to
> save UserID (which is whatever I return from my own function, including
> UserID from User table). Later on, we just call User.Identity.Name to
> retrieve the UserID and it could be used as I like.
> But in ASP.NET 2.0, I just need to add
> <membership defaultProvider="MyMembershipProvider">
> <providers>
> <add name="MyMembershipProvider"
> type="MyMembershipProvider"/>
> </providers>
> </membership>
> to my web.config file, it will handle authentication autimatically. In
> this case how can I pass UserID instead of username to other pages?
>
> Thanks
> Hardy
>
Saturday, March 24, 2012
Pass variable between sub routines
I'm trying to write some code that will create an order number by searching through an order_detail table for the highest numbered order number. Once found, I would like to pass this number to the FillOrder sub routine, which inserts it into the order_detail table. It looks like the findMax routine works, since the response.write statement a the end of it prints out the correct number. However, the response.write statements in the fillorder routine do not display, nor does the table get populated. I think the first problem is that I may not be passing the "highest" variable correctly.
I know the code is probably hack, but I would appreciate help/advice.
Thanks in advance.
Tom
Hi Tom,
Public Sub findMax()
Dim highest As Int32
Dim strMax As String
Const strMaxConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objMaxConn As New SqlConnection(strMaxConn)
Dim dsOrderHead As DataSet
Dim daOrderHead As SqlDataAdapter
dsOrderHead = New DataSet()strMax = "SELECT MAX(order_num) as highest FROM order_header"
Dim CmdMax As New SqlCommand(strMax, objMaxConn)If numOrders = 0 Then
highest = numOrders + 1
End IfIf numOrders > 0 Then
objMaxConn.Open() 'open connection'run SQL command
CmdMax.ExecuteNonQuery()objMaxConn.Close() 'close connection
End If
Response.Write(highest)
FillOrder(highest)
End Sub'populate order_detail table
Public Sub FillOrder(ByVal ordNum As Int32)
'findMax()Const strFillOrdConn As String = "data source=ENVISAGENT1;initial catalog=tsproductsSQL3;integrated security=SSPI;persist security info=False;workstation id=ENVISAGENT1;packet size=4096"
Dim objFillOrdConn As New SqlConnection(strFillOrdConn)
Dim daFillOrd As SqlDataAdapter
Dim strFillOrdSQL As StringDim detNum As Int32 = 0
Response.Write("DetailNum " & detNum)
Response.Write("PRoduct " & grdCart.Items(1).Cells(1).Text)strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (ordNum,detNum,pnum,quan,price)"
Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)
objFillOrdConn.Open()
' Iterate through all rows within shopping cart list
Dim i As IntegerFor i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detaildetNum = detNum + 1
Dim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)CmdFillOrd.ExecuteNonQuery()
Next
objFillOrdConn.Close()
There is no embeded variables in ADO.NET. You have to create command with parameters and use them. Alter your code this way (check types of parameters):
' ...
strFillOrdSQL = "INSERT order_num,detail_num,product_num,quantity,line_item_price INTO order_detail values (@.ordNum,@.detNum,@.pnum,@.quan,@.price)"Dim CmdFillOrd As New SqlCommand(strFillOrdSQL, objFillOrdConn)
CmdFillOrd.Parameters.Add(New SqlParameter("@.ordNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.detNum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.pnum", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.quan", SqlDbType.Int))
CmdFillOrd.Parameters.Add(New SqlParameter("@.price", SqlDbType.Decimal))CmdFillOrd.Parameters[0].Value = ordNum
objFillOrdConn.Open()' Iterate through all rows within shopping cart list
Dim i As IntegerFor i = 0 To grdCart.Items.Count - 1
'for each item in cart,
'insert current order #, detail#,product, quantity & price
'into order_detaildetNum = detNum + 1
CmdFillOrd.Parameters[1].Value = detNumDim pnum As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(1).Text)
Dim price As Decimal = Convert.ToDecimal(grdCart.Items(i).Cells(3).Text)
Dim quan As Int32 = Convert.ToInt32(grdCart.Items(i).Cells(4).Text)CmdFillOrd.Parameters[2].Value = pnum
CmdFillOrd.Parameters[3].Value = quan
CmdFillOrd.Parameters[4].Value = priceCmdFillOrd.ExecuteNonQuery()
Next
Thank-you. I'll give it a try.
Ok I finally got around to trying the code - it looks like it may work, but again, nothing happens after the findMax sub routine listed above. It is as if it isn't even invoking. Also, I took the response.write("Highest = " & highest) statement out, and it still displays the text when the button is clicked. Why does this persist even though the statement is out? Does it also have something to do with the FillOrder sub routing apparantly doing nothing?
Thanks
Tom
There are only two possible explanations for persisting results of response.write:
1. Page is cached and not executed at all
2. You are running wrong version of page
How would I determine which one? I've tried deleting cache files to no avail.
Try to change something visual on page (add some text for example) and see if you receive changes when page is served.
I did all of that.
If you look at the connection strings in the code above, are they creating a cache that persists?
I created new pages and copied the code over to them. I changed the connection strings to "server=localhost;database=tsproductssql3;uid=sa;pwd=sa" and ran it. I got rid of the persistent response.write, and was able to display all of the others. However, I tried again, and got a database (primary key) violation which I have to sort out to see if the problems persist. I'll re-post then.
Thanks for your replies.
Tom
OK, cleared up the persist problem.
If you (or someone) could tell me if the original connection string (above) that I had would have created this cache & persist problem, that would be great. I'm still getting a lot of roadrash fumbling my way through my first ASP.NET project.
Thanks
Tom
Wednesday, March 21, 2012
Passing a CSV file into APSX page and returning query from SQL server using CSV data?
Is this possible basically?
I have a CSV file that contains a list of barcodes, I would like to create a page that will upload this into a temp table of some kind and query a SQL using the CSV file to join the data to the table.
This would then output the result to a list on the page.
Any ideas? As yet I haven't managed to start anything on ASP.net yet!
Of course it's possible. Almost anything is possible. When you get to your coding you should ask the specific questions that you need answered.
Here is one way on how to do this
1. Read your file using FileStream.
2. Create a datatable and its columns.
3. Loop through your file (using FileStream) and populate your datatable.
4. Create a dataview and set to the datatable.
5. Use rowfilter to filter out data you don't want to show.
6. Bind the data to your DataGrid or DataList to display the data onto the page.
Many thanks for your reply, more the kinda reply that I was hoping for.
The method that you have said, trying to understand this:
Does part 3 put the data into the database?
Where do I execute a query/sp to get the correct additional data back? (As more relevant data will be coming back based on a join to the new fields in the table)?
Thanks
Passing a parameter to get results to post to a datagrid
here is my code:
<%@dotnet.itags.org. Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DataSetResults"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_CPAR") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_CPAR") %>'
CommandText='<%# "SELECT * FROM dbo.ListofNonconformities WHERE ""Reference Document"" = ?" %>'
Debug="true" PageSize="10"
><Parameters>
<Parameter Name="@dotnet.itags.org.Reference Document" Value='<%# IIf((Request.Form("FRefDoc") <> Nothing), Request.Form("FRefDoc"), "") %>' Type="WChar" /></Parameters></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="FRefDoc" id="FRefDoc" runat="server">
<p>
<% DDRefDoc.SelectedIndex = DDRefDoc.Items.IndexOf(DDRefDoc.Items.FindByValue(DataSetResults.FieldValue("Reference Document", Nothing) )) %><asp:DropDownList ID="DDRefDoc" runat="server" DataSource="<%# DataSetResults.DefaultView %>" DataTextField="Reference Document" DataValueField="Reference Document"></asp:DropDownList>
<asp:Button ID="BSubmit" runat="server" Text="Submit" /></p>
<p>
<asp:DataGrid id="DataGridResults"
runat="server"
AllowSorting="False"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
ShowFooter="false"
ShowHeader="true"
DataSource="<%# DataSetResults.DefaultView %>"
PagerStyle-Mode="NextPrev"
AllowPaging="true"
AllowCustomPaging="true"
PageSize="<%# DataSetResults.PageSize %>"
VirtualItemCount="<%# DataSetResults.RecordCount %>"
OnPageIndexChanged="DataSetResults.OnDataGridPageIndexChanged"
>
<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<Columns>
<asp:BoundColumn DataField="ISO 9001 Clause"
HeaderText="ISO 9001 Clause"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Expr1"
HeaderText="Expr1"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Action To:"
HeaderText="Action To:"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Description of Nonconformity"
HeaderText="Description of Nonconformity"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verified By"
HeaderText="Verified By"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Submission Date"
HeaderText="Submission Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Completion Date"
HeaderText="Completion Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verification Date"
HeaderText="Verification Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Reference Document"
HeaderText="Reference Document"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Process Owner"
HeaderText="Process Owner"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Remarks"
HeaderText="Remarks"
ReadOnly="true"
Visible="True"/>
</Columns>
</asp:DataGrid>
</p>
<p> </p>
</form>
</body>
</html>that is very good
thank you
passing a string to a regex
this:
(<)(table)
matches this:
<table
<turkey
<amazon
ie, it match < followed by a t or a or b or l or e (at least that's what I
*think* it is doing ;o)
What's the proper way to write out an actual string for matching? I theory,
this should work:
(t)(a)(b)(l)(e)
THe catch is that I'd like to pass 'table' as a string to this. So I'd like
to avoid having to split up the string as an array and then having to build
it like the above.If your string to match against is table, your expression is just the word
table itself, you may want to add RegexOptions.IgnoreCase
"darrel" <notreal@.hotmail.com> wrote in message
news:OGT84LeZEHA.3512@.TK2MSFTNGP12.phx.gbl...
> I'm using a regex and want to find a specific tag, like TABLE
> this:
> (<)(table)
> matches this:
> <table
> <turkey
> <amazon
> ie, it match < followed by a t or a or b or l or e (at least that's what I
> *think* it is doing ;o)
> What's the proper way to write out an actual string for matching? I
theory,
> this should work:
> (t)(a)(b)(l)(e)
> THe catch is that I'd like to pass 'table' as a string to this. So I'd
like
> to avoid having to split up the string as an array and then having to
build
> it like the above.
> If your string to match against is table, your expression is just the
word
> table itself, you may want to add RegexOptions.IgnoreCase
So...this:
(table)
should only match "table"?
That doesn't seem to be happening for me--but maybe I have another issue
with my expression somewhere else. Good suggestion on the IgnorCase option,
though!
-Darrel
> "darrel" <notreal@.hotmail.com> wrote in message
> news:OGT84LeZEHA.3512@.TK2MSFTNGP12.phx.gbl...
> > I'm using a regex and want to find a specific tag, like TABLE
> > this:
> > (<)(table)
> > matches this:
> > <table
> > <turkey
> > <amazon
> > ie, it match < followed by a t or a or b or l or e (at least that's what
I
> > *think* it is doing ;o)
> > What's the proper way to write out an actual string for matching? I
> theory,
> > this should work:
> > (t)(a)(b)(l)(e)
> > THe catch is that I'd like to pass 'table' as a string to this. So I'd
> like
> > to avoid having to split up the string as an array and then having to
> build
> > it like the above.
You dont need the ( ) , its only a grouping construct, however, it should
still work. Post some code so we can take a look.
"darrel" <notreal@.hotmail.com> wrote in message
news:uV4mJjeZEHA.2444@.tk2msftngp13.phx.gbl...
> > If your string to match against is table, your expression is just the
> word
> > table itself, you may want to add RegexOptions.IgnoreCase
> So...this:
> (table)
> should only match "table"?
> That doesn't seem to be happening for me--but maybe I have another issue
> with my expression somewhere else. Good suggestion on the IgnorCase
option,
> though!
> -Darrel
>
> > "darrel" <notreal@.hotmail.com> wrote in message
> > news:OGT84LeZEHA.3512@.TK2MSFTNGP12.phx.gbl...
> > > I'm using a regex and want to find a specific tag, like TABLE
> > > > this:
> > > > (<)(table)
> > > > matches this:
> > > > <table
> > > <turkey
> > > <amazon
> > > > ie, it match < followed by a t or a or b or l or e (at least that's
what
> I
> > > *think* it is doing ;o)
> > > > What's the proper way to write out an actual string for matching? I
> > theory,
> > > this should work:
> > > > (t)(a)(b)(l)(e)
> > > > THe catch is that I'd like to pass 'table' as a string to this. So I'd
> > like
> > > to avoid having to split up the string as an array and then having to
> > build
> > > it like the above.
> >
Here's what I have:
dim r1 as new regex( _
"(?<anythingPreceding>((.|\n)*))" & _
"(?<theTag>(" & tagToFind & "))" & _
"(?<anything>(.[^>/]*))" & _
"(?<theAttribute>(" & attributeToFind & "))" & _
"(?<theEqualsSign>((\s*)=(\s*)))" & _
"(?<theAttributeValue>(.[^\s/>]*))" & _
"(?<anythingSucceeding>((.|\n)*))" _
, RegexOptions.IgnoreCase)
dim m as Match = r1.Match(textToParse)
dim r2 as New Regex("(" & attributeToFind & ")((\s*)=(\s*))(.[^\s/>]*)")
dim s as String = r2.replace(m.tostring, attributeToFind & "=""" &
newAttributeValue & """")
return s
Note that the second group (theTag) is the one I'm concerned with.
If I past "table" to tagToFind, it will match these:
<table width='50' height='12'>
<turkey width='50' height='12'>
<apple width='50' height='12'
So, I *thought* that it was an OR construct.
However, I now notice that it will also match:
<spaghetti width="100%"
So there's obviously something wrong with by Regex in the bigger sense. Let
me stare at it for a bit and see if I can figure this one out ;o)
-Darrel
I'm pretty sure this is the culprit:
"(?<anythingPreceding>((.|\n)*))" & _
"(?<theTag>(" & tagToFind & "))" & _
Or at least part of the problem. The first line should match 'anything' up
until "<table" (I'm passing table to tagToFind)
So, I think I need to look for anything EXCEPT "<table". Correct?
I can't quite get the syntax down, though:
(.|\n(^<table))*
that doesn't seam to work
I figured out what's going on.
I'm finding a large match and then applying a second ReGex to it.
I need to learn how to use the groups ;o)
-Darrel
passing a string to a regex
this:
(< )(table)
matches this:
<table
<turkey
<amazon
ie, it match < followed by a t or a or b or l or e (at least that's what I
*think* it is doing ;o)
What's the proper way to write out an actual string for matching? I theory,
this should work:
(t)(a)(b)(l)(e)
THe catch is that I'd like to pass 'table' as a string to this. So I'd like
to avoid having to split up the string as an array and then having to build
it like the above.If your string to match against is table, your expression is just the word
table itself, you may want to add RegexOptions.IgnoreCase
"darrel" <notreal@.hotmail.com> wrote in message
news:OGT84LeZEHA.3512@.TK2MSFTNGP12.phx.gbl...
> I'm using a regex and want to find a specific tag, like TABLE
> this:
> (< )(table)
> matches this:
> <table
> <turkey
> <amazon
> ie, it match < followed by a t or a or b or l or e (at least that's what I
> *think* it is doing ;o)
> What's the proper way to write out an actual string for matching? I
theory,
> this should work:
> (t)(a)(b)(l)(e)
> THe catch is that I'd like to pass 'table' as a string to this. So I'd
like
> to avoid having to split up the string as an array and then having to
build
> it like the above.
>
> If your string to match against is table, your expression is just the
word
> table itself, you may want to add RegexOptions.IgnoreCase
So...this:
(table)
should only match "table"?
That doesn't seem to be happening for me--but maybe I have another issue
with my expression somewhere else. Good suggestion on the IgnorCase option,
though!
-Darrel
> "darrel" <notreal@.hotmail.com> wrote in message
> news:OGT84LeZEHA.3512@.TK2MSFTNGP12.phx.gbl...
I
> theory,
> like
> build
>
You dont need the ( ) , its only a grouping construct, however, it should
still work. Post some code so we can take a look.
"darrel" <notreal@.hotmail.com> wrote in message
news:uV4mJjeZEHA.2444@.tk2msftngp13.phx.gbl...
> word
> So...this:
> (table)
> should only match "table"?
> That doesn't seem to be happening for me--but maybe I have another issue
> with my expression somewhere else. Good suggestion on the IgnorCase
option,
> though!
> -Darrel
>
what
> I
>
Here's what I have:
dim r1 as new regex( _
"(?<anythingPreceding>((.|\n)*))" & _
"(?<theTag>(" & tagToFind & "))" & _
"(?<anything>(.[^>/]*))" & _
"(?<theAttribute>(" & attributeToFind & "))" & _
"(?<theEqualsSign>((\s*)=(\s*)))" & _
"(?<theAttributeValue>(.[^\s/>]*))" & _
"(?<anythingSucceeding>((.|\n)*))" _
, RegexOptions.IgnoreCase)
dim m as Match = r1.Match(textToParse)
dim r2 as New Regex("(" & attributeToFind & ")((\s*)=(\s*))(.[^\s/>]*)")
dim s as String = r2.replace(m.tostring, attributeToFind & "=""" &
newAttributeValue & """")
return s
Note that the second group (theTag) is the one I'm concerned with.
If I past "table" to tagToFind, it will match these:
<table width='50' height='12'>
<turkey width='50' height='12'>
<apple width='50' height='12'>
So, I *thought* that it was an OR construct.
However, I now notice that it will also match:
<spaghetti width="100%" >
So there's obviously something wrong with by Regex in the bigger sense. Let
me stare at it for a bit and see if I can figure this one out ;o)
-Darrel
I'm pretty sure this is the culprit:
"(?<anythingPreceding>((.|\n)*))" & _
"(?<theTag>(" & tagToFind & "))" & _
Or at least part of the problem. The first line should match 'anything' up
until "<table" (I'm passing table to tagToFind)
So, I think I need to look for anything EXCEPT "<table". Correct?
I can't quite get the syntax down, though:
(.|\n(^<table))*
that doesn't seam to work
I figured out what's going on.
I'm finding a large match and then applying a second ReGex to it.
I need to learn how to use the groups ;o)
-Darrel