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

Friday, March 30, 2012

How to insert the value from the text box (ASP.NET 2.0) to the microsoft sql server 2000 d

Hello Friends,

I have a problem with ASP.net with dynamic data transfer from asp page to microsoft sql server 2000. For example , I have asp web page with one text field and a buttion.When I click the buttion, the value entered in the text field should be transfered from the text field to database.

Kindly See the following section c# code ....

SqlConnection objconnect = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand();

cmd.Connection = objconnect;

cmd.CommandText = " select * from Table_Age where Age = @.Age";

cmd.CommandType = CommandType.Text;

SqlParameter parameter = new SqlParameter();

parameter.ParameterName = "@.Age";

parameter.SqlDbType = SqlDbType.VarChar;

parameter.Direction = ParameterDirection.Output;

parameter.Value = TextBox1.Text;

objconnect.Open();

// Add the parameter to the Parameters collection.

cmd.Parameters.Add(parameter);

SqlDataReader reader = cmd.ExecuteReader();

********************this section c# code is entered under the button control************************************

connection string is mentioned in the web.config file.

In the above c# code , I have a text field , where I entered the age , the value entered in the text field should be sent to database. I have used SqlParameter for selecting the type of data should be sent from ASP.NET 2.0 to the microsoft sql server 2000. I am facing a problem where I am unable to sent the random datas from a text field to the database server.I have a created a database file in the microsoft server 2000.

after the excution of the fIeld value is assinged to NULL in the main database i.e microsoft the sql server 2000.

Can anyone help with this issue.

My mail id phijop@.hotmail.com

- PHIJO MATHEW PHILIP.

Hi

Remove :

parameter.Direction = ParameterDirection.Output;

since your direction should be input.

How to Insert Multiple Records into sql 2000 table at once ?

hello,
I am new to Slq 2000 Database,Now I create an asp.net application with sql 2000,
in my database I have two 2 table lets' say "OrderHead" and "OrderDetail",they look like this:
OrderHead orderdetail
--order no --orderno
--issuedate --itemname
--supplier --desccription
--amount --price
--Qty
Now I created a user-defined Collection class to storage order detail data in memory
and bind to a datagrid control.
I can transfer Collection data to xml file ,my problem as below :
There have multiple records data in my xml file,and I want to send the xml file as argument to a store procedure in sql 2000

anyone can give me some advise or some sample code ?

thanks in advanced!See links below:

1. http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
2. http://www.eggheadcafe.com/articles/20030627c.asp|||hi, thanks a lot,I will browse the web page you give me .

Wednesday, March 28, 2012

how to insert data in to two tables?

hi,

i have got a problem, iam creating an asp.net application, but i pretend to insert data in two different tables, but i have no ideia how to do this.Can you help to solve this problem? please........

So, you need to insert data into two different tables? What database are you using? If you are using SQL or MSDE, you would use 2 insert statements or a stored procedure.|||

scosta wrote:

hi,

i have got a problem, iam creating an asp.net application, but ipretend to insert data in two different tables, but i have no ideia howto do this.Can you help to solve this problem? please........


This is as simple as executing two SQL INSERTS in sequence or as complicated as writing a stored proc that does the same thing.
Time to pick up an introductory book on SQL Server and ADO.NET my friend.
|||

iam using Sql, and i want to use the way to solve the problem, or 2 insert statements or a stored procedure.

how to insert data in to two tables?

hi,

iam creating an asp.net application the database is created on the SQLSERVER, but i have a problem, i pretend to insert data in to 2 tables and i have no ideia how to do this. Can you help me to solve this problem? Please....

you would need 2 insert statements. check out books online for syntax on INSERT. You could also use stored procedures to have all the inserts in it so you can get your job done in one trip to the server.sql

How to insert BLOB data Using Store Procedure

Hi,

Can we insert BLOB data using store procedure using Oracle and ASP.Net.

I have inserted BLOB data using insert command, now i want to insert that BLOB via store procedure...

any links/tips will be helpful...

Hi,

Of course, you can use stored procedure to insert BLOB data. Use some data type that takes byte array as parameter, and you can insert into the table. You can just use the INSERT command as the content of the stored procedure.

How to insert a xml file in sql server database using asp.net?

hii,

i want to insert a xml file into the sql server using asp.net.can sm1 help me wth d coding part?What server version you use?

In 2005 - there is XML datatype and almost unlimited size of XML.

In 2000 - for character datatype you limited to 8000 characters unless you are going to use text datatype.sql

Monday, March 26, 2012

How to insert a row with lowest possible key?

Hi, this seems to be an easy question but I can't find a quick answer to it.

I have an asp page that communicates with a database and I want the following example to work...

Insert 5 records into the DB with primary keys 1-5.

Remove record with key number 2.

Now, if I insert a new record I want it to take the smallest available key number (in this case number 2). This will save space in the database and keep the key numbers from increasing forever.

Does auto increment work like this?

If not, how do I do it?

Thanks for any replies!

Niklas

Auto-increment doesn't work like this.

I'm not sure that you reasons for doing this are sound. I don't think it'll save space really. An INT is an INT so you will only be storing 4bytes no matter what the size of the number. And while they will increase forever, its got to be a pretty big system to hit the limit of 2,147,483,647!!

However, i guess you could do it, but you'll need to run a check like SELECT MIN(Value) FROM Table and then subtracting 1 from that to get your value before running your INSERT statement.

|||

Auto numbers won't fill the gap. You have to write your own logic for this. It might degrade your query performance.

Because,

1. You need to find if there is any gap in existing data

2. You have to find the minimum gap to fill

3. If you already use the auto increment on the current column you have to disable it to fill the gap.

4. If step-1 & step-2 fails then you have to continue with auto increment

Finally,

5. If the concurrent users (let say 2 users) try to insert same id, one will be pass. Another user's transaction

will fail, you have to take care this failure and again you have to find the gap from step1. If n users try to

access this logic the Nth users may need to spend more time to insert his record.

Do you want to continue still?

|||This looks really strange, but it's working for me. The query in red is where the magic happens; everything else is just creating a test environment (run the whole thing in AdventureWorks/Northwind/pubs to see it in action).

Code Snippet

--Make a test table
IF object_id('junk') IS NOT NULL
DROP TABLE junk
GO
CREATE TABLE junk (
id int identity(1, 1),
data char(4)
)
GO

--Put in some test data
SET NOCOUNT ON
DECLARE @.i int
SET @.i = 1
WHILE @.i <= 100
BEGIN
INSERT INTO junk (data) VALUES (@.i)
SET @.i = @.i + 1
END
SET NOCOUNT OFF
GO

--Remove some records
DELETE FROM junk WHERE id IN (4, 5, 56, 17, 9, 82)
GO

--Find the lowest available number
SELECT MIN(j1.id) + 1 AS [next]
FROM junk j1
LEFT OUTER JOIN junk j2
ON j1.id + 1 = j2.id
WHERE j2.id IS NULL


|||Another issue is that if your database does not have cascading deletes, the new records may have foreign key usage in other tables that is not intended for the current record.sql

Monday, March 19, 2012

How to improve performance with a join between 2 table from 2 SQL Servers

I am making a ASP.NET web application that involves 2 SQL Server(A & B).

I created a view in SQL server A pointing to the table in SQL Server B. I found out my application will run REALLY slow when accessing such a view. so I try to avoid using them. But in the case of 2 table joining from 2 different SQL Servers, I have no choice.

Can anyone help me with this?

Thanks!

No you don't need a View which is a query rewrite but you need the OpenRowset function. Try the link below for more.

http://msdn2.microsoft.com/en-us/library/ms190312.aspx

|||that is exactly how I create my view(I used openrowset to create it). So what you suggest is just same thing as what I am doing. It is so slow, I don't know how to improve it.|||

Can anybody have any suggestion except using "OpenRowset" function? Because it is slow and it is what I am using.

I found out that the Collate Character set of the 2 SQL Server is different, will this affect the performance? If so, how could I change it?

Thanks!

|||

When you join between 2 seperate servers, it is possible that all of the data from one servers table is moving to the other server. Possibly even data that is not ultimately required by your join. This is what i would suspect as the cause of the performance issue.

Ive seen similar issue with Access applications ive supported when the Access db was joining a local Access table to a linked sql table. It usually worked ok if one of the tables was very small, but if both tables were large, the application would virtually grind to a halt.

My solution to speed it up was to prefetch exactly the data i needed from the remote server into a temp table in my local server. Then i would join to the temp table.

If i couldnt construct a query to get exactly what i needed, i would added as many constraints as possible to try to eliminate as much unnecessary data as possible from being pulled from the remote server.

how to improve "update" speed

hi

in asp.net,i used sql server to store records.

in a table has 1 million records,but when i update the record,it is very slowly.

is "create index" helpful for "update" operation?

i need help,thanks a lot.

First ensure that you have properly created index on you table and primary key.

Second ensure that you have data in table only for one business period( on principle one year).

Make shrink on your data table.

Refactor your data index.

This will help you.

|||

Post the update statement you have as well as all the table information. Do an "EXEC sp_Help TableName" in your query analyzer and post the results here.

|||

Hi ndinakar:

mytable has 100,000 records, i use "exec sp_help mytable",its result is :

Name Owner Type Created_datetime

mytable dbo user table 2007-11-30 9:34:21

can i get further information

thanks a lot

|||

Hi yugiant,

Based on my understanding, you are now tring to creating indexes in your sql server database in order to improve your update performance. If I've understood you wrong, please feel free to tell me, thanks.

Yes I think using index is a good idea. Using indexes in your database will save a lot of time for locating the specific record. And since we need to first locate the record before updating it, I think using index is a great help for improving updating performance. exec sp_help will list properties of your table, including all the indexex you have made to your datatable. You can also get your datatable index information from Object Explorer(in the Indexes tree view node).

I strongly suggesting you reading this:http://msdn2.microsoft.com/en-us/library/ms189051.aspx I think it will be much of help to solve your problem. thanks.

Hope my suggestion helps

Friday, March 9, 2012

How to Import and Export CSV File

Hi frnz ,

i want to know how to import a CSV File and export CSV File From database SQLSERVER-2005 Using ASP.NET With C#

IF any one knows Help me

Vinnu

http://www.codeproject.com/aspnet/ImportExportCSV.asp

Wednesday, March 7, 2012

how to implement transactions in sql server 2000

hi,

i have developed an web-enabled database application using ASp.net, C# and sql server 2000.

now i want to implement transaction controls over the same

can anyone plz help me in implementing the same?

thanks in advance

Transaction comes in three part code, the shopping cart, the C# transaction and the stored procs. I would look at the Commerce starter kit but buy Programming .NET by Jeff Prosise it has all the C# code including Session state management. Hope this helps.|||

Hi,

thanx for the suggestion. but i cant find that book over here. Is there any better tutorial whichs online and gives the information abt transactions?

|||

This is the code from the book and I also added link to the Commerce Starter kit it is in VB but you could use that to understand the C# code. Hope this helps.


Congo.aspx
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>

<html>
<body>
<h1>Congo.com</h1>
<form runat="server">
<table width="100%" bgcolor="teal">
<tr>
<td>
<asp:Button Text="View Cart" OnClick="OnViewCart"
RunAt="server" />
</td>
</tr>
</table>
<br>
<center>
<asp:DataGrid ID="MyDataGrid"
AutoGenerateColumns="false" CellPadding="2"
BorderWidth="1" BorderColor="lightgray"
Font-Name="Verdana" Font-Size="8pt"
GridLines="vertical" Width="90%"
OnItemCommand="OnItemCommand" RunAt="server">
<Columns>
<asp:BoundColumn HeaderText="Item ID"
DataField="title_id" />
<asp:BoundColumn HeaderText="Title"
DataField="title" />
<asp:BoundColumn HeaderText="Price"
DataField="price" DataFormatString="{0:c}"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="right" />
<asp:ButtonColumn HeaderText="Action" Text="Add to Cart"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center"
CommandName="AddToCart" />
</Columns>
<HeaderStyle BackColor="teal" ForeColor="white"
Font-Bold="true" />
<ItemStyle BackColor="white" ForeColor="darkblue" />
<AlternatingItemStyle BackColor="beige"
ForeColor="darkblue" />
</asp:DataGrid>
</center>
</form>
</body>
</html>

<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
if (!IsPostBack) {
string ConnectString =
ConfigurationSettings.AppSettings["connectString"];
SqlDataAdapter adapter = new SqlDataAdapter
("select * from titles where price != 0", ConnectString);
DataSet ds = new DataSet ();
adapter.Fill (ds);
MyDataGrid.DataSource = ds;
MyDataGrid.DataBind ();
}
}

void OnItemCommand (Object sender, DataGridCommandEventArgs e)
{
if (e.CommandName == "AddToCart") {
BookOrder order = new BookOrder (e.Item.Cells[0].Text,
e.Item.Cells[1].Text, Convert.ToDecimal
(e.Item.Cells[2].Text.Substring (1)), 1);
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null)
cart.AddOrder (order);
}
}

void OnViewCart (Object sender, EventArgs e)
{
Response.Redirect ("ViewCart.aspx");
}
</script>
ViewCart.aspx
<html>
<body>
<h1>Shopping Cart</h1>
<form runat="server">
<table width="100%" bgcolor="teal">
<tr>
<td>
<asp:Button Text="Return to Shopping" OnClick="OnShop"
RunAt="server" />
</td>
</tr>
</table>
<br>
<center>
<asp:DataGrid ID="MyDataGrid"
AutoGenerateColumns="false" CellPadding="2"
BorderWidth="1" BorderColor="lightgray"
Font-Name="Verdana" Font-Size="8pt"
GridLines="vertical" Width="90%"
OnItemCommand="OnItemCommand" RunAt="server">
<Columns>
<asp:BoundColumn HeaderText="Item ID"
DataField="ItemID" />
<asp:BoundColumn HeaderText="Title"
DataField="Title" />
<asp:BoundColumn HeaderText="Price"
DataField="Price" DataFormatString="{0:c}"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="right" />
<asp:BoundColumn HeaderText="Quantity"
DataField="Quantity"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center" />
<asp:ButtonColumn HeaderText="Action" Text="Remove"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center"
CommandName="RemoveFromCart" />
</Columns>
<HeaderStyle BackColor="teal" ForeColor="white"
Font-Bold="true" />
<ItemStyle BackColor="white" ForeColor="darkblue" />
<AlternatingItemStyle BackColor="beige"
ForeColor="darkblue" />
</asp:DataGrid>
</center>
<h3><asp:Label ID= "Total" RunAt="server" /></h3>
</form>
</body>
</html>

<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null) {
MyDataGrid.DataSource = cart.Orders;
MyDataGrid.DataBind ();
Total.Text = String.Format ("Total Cost: {0:c}",
cart.TotalCost);
}
}

void OnItemCommand (Object sender, DataGridCommandEventArgs e)
{
if (e.CommandName == "RemoveFromCart") {
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null) {
cart.RemoveOrder (e.Item.Cells[0].Text);
MyDataGrid.DataBind ();
Total.Text = String.Format ("Total Cost: {0:c}",
cart.TotalCost);
}
}
}

public void OnShop (Object sender, EventArgs e)
{
Response.Redirect ("Congo.aspx");
}
</script>
Congo.cs
using System;
using System.Collections;

[Serializable]
public class BookOrder
{
string _ItemID;
string _Title;
decimal _Price;
int _Quantity;

public string ItemID
{
get { return _ItemID; }
set { _ItemID = value; }
}

public string Title
{
get { return _Title; }
set { _Title = value; }
}

public decimal Price
{
get { return _Price; }
set { _Price = value; }
}

public int Quantity
{
get { return _Quantity; }
set { _Quantity = value; }
}

public BookOrder (string ItemID, string Title, decimal Price,
int Quantity)
{
_ItemID = ItemID;
_Title = Title;
_Price = Price;
_Quantity = Quantity;
}
}

[Serializable]
public class ShoppingCart
{
Hashtable _Orders = new Hashtable ();

public ICollection Orders
{
get { return _Orders.Values; }
}

public decimal TotalCost
{
get
{
decimal total = 0;
foreach (DictionaryEntry entry in _Orders) {
BookOrder order = (BookOrder) entry.Value;
total += (order.Price * order.Quantity);
}
return total;
}
}

public void AddOrder (BookOrder Order)
{
BookOrder order = (BookOrder) _Orders[Order.ItemID];
if (order != null)
order.Quantity += Order.Quantity;
else
_Orders.Add (Order.ItemID, Order);
}

public void RemoveOrder (string ItemID)
{
if (_Orders[ItemID] != null)
_Orders.Remove (ItemID);
}
}


http://asp.net/CommerceStarterKit/docs/docs.htm

|||

It's not a book. "Starter Kit"

http://asp.net/Default.aspx?tabindex=8&tabid=47

How to implement the sqlserver ReportServices in ASP Page

Is it possible to use SQL Server Reporting Service in ASP Page? Anybody can help me.

No. It's a .net control. ASP can only work with ActiveX components, not .Net bases pages. It is possible to include an aspx rendered page inside asp, but then you would still need to work with asp.net. You can directly link to the reporting services web application.

How to implement the sqlserver ReportServices in ASP Page

Is it possible to use SQL Server Reporting Service in ASP Page? Anybody can help me.

No. It's a .net control. ASP can only work with ActiveX components, not .Net bases pages. It is possible to include an aspx rendered page inside asp, but then you would still need to work with asp.net. You can directly link to the reporting services web application.