Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 28, 2012

how to save listbox multiple select values

Hi,

I have an ASP.NET form that stores it's data in MSDE but I just added a multi-select ListBox to the form and I'm having a hard time coming up with a way of writing that data to the database. Should I write the values into a column on the same table where I store the rest of the data from the form (values separated by a comma) or shouild I create another table (one to many) and store the data there. I like the second option, but I'm not sure how to loop through each value and write it to the database table.

I grab the values for the selection as follow:

foreach (ListItem lstItem in lbAttendees.Items)
{
if (lstItem.Selected == true)
{
grpList.Add(lstItem.Value.ToString());
}
}

but I'm not sure on what to do next and could use some help.

Thanks
Germanoshouldn't lbAttendees have .SelectedItems?

Next, you should be passing the values to the database through sql or other dataaccess means.|||>>Should I write the values into a column on the same table where I store the rest of the data from the form (values separated by a comma) or shouild I create another table (one to many) and store the data there.

I would strongly suggest option 2 (Normalize).

>>I'm not sure how to loop through each value and write it to the database table.

Well you have some options.

i) Loop through your items on the client and perform inserts (one row at a time).

ii) Package up the values as an xml chunk and use openxml to insert (set based method, less chatty)

ii) Package up the values as a delimited string and perform parsing and insert at the server.

And there are others (using OO: collections, persistance frameworks mechanisms, etc..)sql

Monday, March 26, 2012

How to Save custome object AS IS in SQL Server

Hi there,
Not sure if this is the right place to ask.
I have a custom object in ASP.NET called TransactionResponseObject.
And I want to save this object AS IS - in one piece in SQL Server 2005 (instead of taking each and every property of it and individually saving it into separate columsn of a table in the database).

Question:
1). What type of SQL Server 2005 datatype will I be using in this case ?

2). Is there a good and easy tutorial on converting a custom object into XML format? and perhaps saving the xml into the database (I feel it's just an extra step - meaning extra processing which i want to avoid).

Thanks

TorontoMale

you can probaly serialize the object and store either in an xml column with or witouth a schema, preferably with, or as a binary, or as a string, then load up that way.

you have many options on storing the serialized object.

Wednesday, March 21, 2012

How to run asp page from sql server?

Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u guys
really understand my problem. if u have any doubt reply me. thanks in advance.
-suresh
No. There is not. All of the SQL Server executions need to be run
non-interactively. ASP is an interactive system. Why not just code some
ActiveX script or COM object to execute?
You can use the xp_cmdshell or any of the sp_OA stored procedures.
What is that ASP code trying to do?
Sincerely,
Anthony Thomas

"suresh" <suresh@.discussions.microsoft.com> wrote in message
news:8C292B13-4E4A-442E-AFD1-A36E082D112C@.microsoft.com...
Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u
guys
really understand my problem. if u have any doubt reply me. thanks in
advance.
-suresh

How to run asp page from sql server?

Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u guys
really understand my problem. if u have any doubt reply me. thanks in advance.
-sureshNo. There is not. All of the SQL Server executions need to be run
non-interactively. ASP is an interactive system. Why not just code some
ActiveX script or COM object to execute?
You can use the xp_cmdshell or any of the sp_OA stored procedures.
What is that ASP code trying to do?
Sincerely,
Anthony Thomas
"suresh" <suresh@.discussions.microsoft.com> wrote in message
news:8C292B13-4E4A-442E-AFD1-A36E082D112C@.microsoft.com...
Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u
guys
really understand my problem. if u have any doubt reply me. thanks in
advance.
-sureshsql

How to run asp page from sql server?

Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u guy
s
really understand my problem. if u have any doubt reply me. thanks in advanc
e.
-sureshNo. There is not. All of the SQL Server executions need to be run
non-interactively. ASP is an interactive system. Why not just code some
ActiveX script or COM object to execute?
You can use the xp_cmdshell or any of the sp_OA stored procedures.
What is that ASP code trying to do?
Sincerely,
Anthony Thomas
"suresh" <suresh@.discussions.microsoft.com> wrote in message
news:8C292B13-4E4A-442E-AFD1-A36E082D112C@.microsoft.com...
Hi ,
I have one asp page that send sms to the users. i just want to send that
sms in a particular time. Since i coudnt execute that asp page in a
particular time, i just want to make use of sql server job Schedule. i used
the sql server job to run that particular asp page using xp_cmdshell stored
procedure. i gave the following pl/sql statement to run that asp page.
exec xp_cmdshell "start test.asp"
but that job exectues sucessfully. but actually that page is not exected. is
there any other way to run a asp web page using sql job option? i hope u
guys
really understand my problem. if u have any doubt reply me. thanks in
advance.
-suresh

Monday, March 12, 2012

How to Return SqlDataReader and return value (page count) from SPROC

This is my function, it returns SQLDataReader to DATALIST control. Howto return page number with the SQLDataReader set ? sql server 2005,asp.net 2.0

Function get_all_events() As SqlDataReader
Dim myConnection As NewSqlConnection(ConfigurationManager.AppSettings("........."))
Dim myCommand As New SqlCommand("EVENTS_LIST_BY_REGION_ALL", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

Dim parameterState As New SqlParameter("@.State", SqlDbType.VarChar, 2)
parameterState.Value = Request.Params("State")
myCommand.Parameters.Add(parameterState)

Dim parameterPagesize As New SqlParameter("@.pagesize", SqlDbType.Int, 4)
parameterPagesize.Value = 20
myCommand.Parameters.Add(parameterPagesize)

Dim parameterPagenum As New SqlParameter("@.pageNum", SqlDbType.Int, 4)
parameterPagenum.Value = pn1.SelectedPage
myCommand.Parameters.Add(parameterPagenum)

Dim parameterPageCount As New SqlParameter("@.pagecount", SqlDbType.Int, 4)
parameterPageCount.Direction = ParameterDirection.ReturnValue
myCommand.Parameters.Add(parameterPageCount)

myConnection.Open()
'myCommand.ExecuteReader(CommandBehavior.CloseConnection)
'pages = CType(myCommand.Parameters("@.pagecount").Value, Integer)
Return myCommand.ExecuteReader(CommandBehavior.CloseConnection)
End Function

Variable Pages is global integer.

This is what i am calling
DataList1.DataSource = get_all_events()
DataList1.DataBind()

How to return records and also the return value of pagecount ? i tried many options, nothing work. Please help !!. I am struck

please any help ? finally following code works without error, but still not returning any return value (pagecount) along with the list of records.

Dim MyReader As SqlDataReader
Dim myConnection As New SqlConnection(ConfigurationManager.AppSettings("Dx918Aveb8ax81"))
Dim myCommand As New SqlCommand("EVENTS_LIST_BY_REGION_ALL", myConnection)
myCommand.CommandType = CommandType.StoredProcedure

Dim parameterregion As New SqlParameter("@.Region", SqlDbType.VarChar, 5)
parameterregion.Value = Request.Params("reg")
myCommand.Parameters.Add(parameterregion)

Dim parameterPagesize As New SqlParameter("@.pagesize", SqlDbType.Int, 4)
parameterPagesize.Value = 10
myCommand.Parameters.Add(parameterPagesize)

Dim parameterPagenum As New SqlParameter("@.pageNum", SqlDbType.Int, 4)
parameterPagenum.Value = pn1.SelectedPage
myCommand.Parameters.Add(parameterPagenum)

Dim parameterPageCount As New SqlParameter("@.pagecount", SqlDbType.Int, 4)
parameterPageCount.Direction = ParameterDirection.ReturnValue
myCommand.Parameters.Add(parameterPageCount)

myConnection.Open()
MyReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
pages = myCommand.Parameters("@.pagecount").Value
DataList1.DataSource = MyReader
DataList1.DataBind()
myCommand.Dispose()
myConnection.Dispose()
Response.Write(pages)

|||Output parameters and return values are not available until after aDataReader is closed (which you should add after your DataBind()).|||thank you. I will try that today!!

how to return a value in a stored procedure?

Hi,
i use a stored procedure for my asp.net application which must return a
value: (number of items). How can i do that?
I tried this but don't know how to giive te found value back.
Thansk
Chris
ALTER PROCEDURE [dbo].[mysp]
AS
declare @.returnValue int
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select COUNT(DISTINCT numberofitems) from items
END
set @.returnValue = ?
return @.returnValueYou need to use an output parameter. Have a look at these:
http://msdn2.microsoft.com/en-us/library/ms971497.aspx
http://www.sommarskog.se/share_data.html
http://www.informit.com/articles/ar...8&seqNum=9&rl=1
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"Chris" <ch@.spam.it> wrote in message
news:%23TUm6byIIHA.5860@.TK2MSFTNGP04.phx.gbl...
> Hi,
> i use a stored procedure for my asp.net application which must return a
> value: (number of items). How can i do that?
> I tried this but don't know how to giive te found value back.
> Thansk
> Chris
>
> ALTER PROCEDURE [dbo].[mysp]
> AS
> declare @.returnValue int
> BEGIN
> -- SET NOCOUNT ON added to prevent extra result sets from
> -- interfering with SELECT statements.
> SET NOCOUNT ON;
> -- Insert statements for procedure here
> select COUNT(DISTINCT numberofitems) from items
> END
> set @.returnValue = ?
> return @.returnValue
>|||Thanks
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> schreef in bericht
news:erDK$IzIIHA.4712@.TK2MSFTNGP04.phx.gbl...
> You need to use an output parameter. Have a look at these:
> http://msdn2.microsoft.com/en-us/library/ms971497.aspx
> http://www.sommarskog.se/share_data.html
> http://www.informit.com/articles/ar...8&seqNum=9&rl=1
>
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
> "Chris" <ch@.spam.it> wrote in message
> news:%23TUm6byIIHA.5860@.TK2MSFTNGP04.phx.gbl...
>|||This is an example I just posted to my book's "Ask Answer" support site. It
calls a SP that returns the Identity value as a Return value. No, you don't
need an output parameter for this--the Return will work fine if you can pass
back an Int.
/****** Object: Stored Procedure dbo.Author_Insert Script Date: 12/7/98
5:08:41 PM ******/
ALTER Procedure Author_Insert @.Author varchar(50), @.Year_Born smallint
As
INSERT INTO Authors
( Author, Year_Born)
VALUES ( @.Author, @.Year_born )
RETURN SCOPE_IDENTITY()
'Copyright (c) 2007 Beta V Corporation. All rights reserved.
' For demonstration purposes only. No warranty of any kind expressed or
implied.
Imports System.Data.SqlClient
Public Class Form1
Dim cn As SqlConnection
Dim cmd As SqlCommand
Sub New()
InitializeComponent()
cn = New SqlConnection(My.Settings.BiblioConnection)
End Sub
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsert.Click
Dim intRa, intIdentity As Integer
Try
cmd = New SqlCommand("Author_Insert", cn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@.Author", tbAuthor.Text)
.Parameters.AddWithValue("@.Year_Born", tbYearBorn.Text)
.Parameters.Add("@.ReturnValue", SqlDbType.Int) _
.Direction = ParameterDirection.ReturnValue ' To capture
RETURN value
cn.Open()
intRa = .ExecuteNonQuery
intIdentity = CInt(.Parameters("@.ReturnValue").Value)
End With
If intRa = 1 Then
MsgBox(String.Format("Row inserted. Identity value {0}", _
intIdentity), MsgBoxStyle.Exclamation)
Else
MsgBox("Insert failed")
End If
Catch exsql As SqlException
MessageBox.Show(exsql.ToString)
Catch ex As Exception
Debug.Assert(False, ex.ToString)
Finally
cn.Close()
End Try
End Sub
End Class
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
----
---
"Chris" <ch@.spam.it> wrote in message
news:%23TUm6byIIHA.5860@.TK2MSFTNGP04.phx.gbl...
> Hi,
> i use a stored procedure for my asp.net application which must return a
> value: (number of items). How can i do that?
> I tried this but don't know how to giive te found value back.
> Thansk
> Chris
>
> ALTER PROCEDURE [dbo].[mysp]
> AS
> declare @.returnValue int
> BEGIN
> -- SET NOCOUNT ON added to prevent extra result sets from
> -- interfering with SELECT statements.
> SET NOCOUNT ON;
> -- Insert statements for procedure here
> select COUNT(DISTINCT numberofitems) from items
> END
> set @.returnValue = ?
> return @.returnValue
>

Friday, February 24, 2012

how to retrieve datas from a SqlDataSource

Hi! I'm a novice in asp .net

I've a SqlDataSource component on an Aspx page.
In the associated C# file, I would like to use datas from the query stored in the SqlDataSource component.

How to do this?

Thanxs :)

An example

<%@.PageLanguage="C#" %>

<%@.ImportNamespace="System.Data" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<scriptrunat="server">

protected void Page_Load(object sender, EventArgs e)

{

DataView dv = (DataView)SqlDataSource1.Select(new DataSourceSelectArguments());

DataTable dt = dv.Table;

// display table

bool pagesToDo = true;

int index = 0;

while (pagesToDo)

{

Table t = GetDisplayTable(dt);

t.CssClass = "PageBreakStyle";

Controls.Add(t);

int nextPageEndsAt = index + 10;

while (index < nextPageEndsAt && pagesToDo)

{

TableRow tr = new TableRow();

t.Rows.Add(tr);

foreach (DataColumn dc in dt.Columns)

{

TableCell tc = new TableCell();

tr.Cells.Add(tc);

tc.Text = dt.Rows[index][dc.ColumnName].ToString();

}

index++;

if (index == dt.Rows.Count)

{

pagesToDo = false;

break;

}

}

}

}

Table GetDisplayTable(DataTable dt)

{

Table t =newTable();

TableHeaderRow thr =newTableHeaderRow();

t.Rows.Add(thr);

foreach (DataColumn dcin dt.Columns)

{

TableHeaderCell thc =newTableHeaderCell();

thc.Text = dc.ColumnName;

thr.Cells.Add(thc);

}

return t;

}

</script>

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<styletype="text/css">

.PageBreakStyle

{

page-break-after:always;

}

</style>

</head>

<body>

<formid="form1"runat="server">

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

SelectCommand="SELECT [ProductID], [ProductName] FROM [Products]"></asp:SqlDataSource>

</form>

</body>

</html>

|||

Thanks, it works!

very cool man ^^

How to retrieve Data from SQL SERVER 2000 ?

Hello,

Im using Visual Studio 2005 to code ASP.NET

How to query my MS SQL SERVER 2000 to retrieve data from my DataBase?

Ive tried some tutorials, but i kept giving me errors
Can you put a simple source code to retrieve something like "select userID, Name, Age from Users"

Thank you,

Are you able to connect to your database?
|||First have you tried the gridview control that auto creates your select statement by you defining options in VS 2005 wizards?

Check out this tutorial on how to do a grid with a simple select statement.
http://www.devx.com/dotnet/Article/22141