473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Datasource question

I have a practice website (I'm a newbie) that I want to use the
Northwind SQL Server sample database in. First, do I upload the
database into my App_Data folder of my website? Also I have a
textbook .aspx I'm doing a lab on with the following code (what I'm
wondering is do I change the "local" to the complete URL of my
website? Also should I drag the Northwind object over my .aspx form to
create the Data Adapter or is that handled in the code below? Also in
HTML code following, where should I place A and where should I place
B?):

A) Imports System.Data
Imports.System.Data.SqlClient

B) Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Dim cnn As SqlConnection("Data Source=(local);" & _
New SqlConnection("Data Source=(local);" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI")
Dim ds As DataSet = New DataSet()
Dim da As SqlAdapter = _
New SqlDataAdapter()
Dim cmdSelect As SqlCommand = _
cnn.CreateCommand()
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = _
"SELECT CustomerID, CompanyName, " & _
"ContactName FROM Customers"
Dim cmdInsert As SqlCommand = _
cnn.CreateCommand()
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = _
"INSERT INTO Customers " & _
"(CustomerID, CompanyName, ContactName) " & _
"VALUES(@CustomerID, @CompanyName, _
"@ContactName)"
cmdInsert.Parameters.Add("@CustomerID", _
SqlDbType.NChar, _
5, "CustomerID")
cmdInsert.Parameters.Add("@CompanyName", _
SqlDbType.NVarChar, _
40, "CompanyName")
cmdInsert.Parameters.Add("@ContactName", _
SqlDbType.NVChar, _
30, "ContactName")
cmdInsert.Parameters("@CustomerID"), _
SourceVersion = _
DataRowVersion.Original
Da.SelectCommand = cmdSelect
Da.InsertCommand = cmdInsert
Da.Fill(ds, "Customers")
Dim dr As DataRow = ds.Tables( _
"Customers").NewRow()
Dr(0) = txtCustomerID.Text
Dr(1) = txtCompanyName.Text
Dr(2) = txtContactName.Text
Ds.Tables("Customers").Rows.Add(dr)
Da.Update(ds, "Customers")
lblResults.Text = "Row added!"
End If
End Sub

<%@ Page Language="VB" %>

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

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body bgcolor="#00ffcc">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtCustomerID" runat="server" Style="z-index:
100; left: 256px; position: absolute;
top: 240px" BorderStyle="Ridge"></asp:TextBox>
<asp:TextBox ID="txtCompanyName" runat="server" Style="z-
index: 101; left: 256px; position: absolute;
top: 272px"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Style="z-index: 102;
left: 344px; position: absolute;
top: 360px" Text="Add" Width="128px"
OnClick="btnAdd_Click" />
<asp:TextBox ID="txtContactName" runat="server" Style="z-
index: 103; left: 256px;
position: absolute; top: 304px"></asp:TextBox>
<asp:Label ID="Label1" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 104; left: 104px; position: absolute; top:
240px" Text="Customer ID"
Width="120px"></asp:Label>
<asp:Label ID="Label2" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 105; left: 104px; position: absolute; top:
304px" Text="Contact Name"
Width="120px"></asp:Label>
<asp:Label ID="Label3" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 106; left: 104px; position: absolute; top:
272px" Text="Company Name"
Width="120px"></asp:Label>
<asp:Label ID="Label4" runat="server" BackColor="White"
ForeColor="Black" Style="z-index: 108;
left: 88px; position: absolute; top: 432px"
Text="[lblResults]" Width="440px"></asp:Label>

</div>
</form>
</body>
</html>

May 2 '07 #1
1 1138
First, do I upload the database into my App_Data folder of my website?

I would do so.
do I change the "local" to the complete URL of my
website?
If your SQL Server is in the same box as your web server you can leave
local. Otherwise write the name of the server and instance name. Example:
MYSERVER\SQLEXPRESS
>where should I place A and where should I place
B?):
Are you using Visual Studio to build your web site? If the Page_Load method
should be there as default when you create a new ASPX page with code-behind
enable. If youd using a text editor then the proper way to put A is above
the class and namespace declaration and B goes inside the class, since it's
a method.

Hope this helps,

Regards,

Michel Bechelani

--
This post is provided "AS IS" with no explicit or implied warranties.

"slinky" <ca***************@yahoo.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I have a practice website (I'm a newbie) that I want to use the
Northwind SQL Server sample database in. First, do I upload the
database into my App_Data folder of my website? Also I have a
textbook .aspx I'm doing a lab on with the following code (what I'm
wondering is do I change the "local" to the complete URL of my
website? Also should I drag the Northwind object over my .aspx form to
create the Data Adapter or is that handled in the code below? Also in
HTML code following, where should I place A and where should I place
B?):

A) Imports System.Data
Imports.System.Data.SqlClient

B) Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Dim cnn As SqlConnection("Data Source=(local);" & _
New SqlConnection("Data Source=(local);" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI")
Dim ds As DataSet = New DataSet()
Dim da As SqlAdapter = _
New SqlDataAdapter()
Dim cmdSelect As SqlCommand = _
cnn.CreateCommand()
cmdSelect.CommandType = CommandType.Text
cmdSelect.CommandText = _
"SELECT CustomerID, CompanyName, " & _
"ContactName FROM Customers"
Dim cmdInsert As SqlCommand = _
cnn.CreateCommand()
cmdInsert.CommandType = CommandType.Text
cmdInsert.CommandText = _
"INSERT INTO Customers " & _
"(CustomerID, CompanyName, ContactName) " & _
"VALUES(@CustomerID, @CompanyName, _
"@ContactName)"
cmdInsert.Parameters.Add("@CustomerID", _
SqlDbType.NChar, _
5, "CustomerID")
cmdInsert.Parameters.Add("@CompanyName", _
SqlDbType.NVarChar, _
40, "CompanyName")
cmdInsert.Parameters.Add("@ContactName", _
SqlDbType.NVChar, _
30, "ContactName")
cmdInsert.Parameters("@CustomerID"), _
SourceVersion = _
DataRowVersion.Original
Da.SelectCommand = cmdSelect
Da.InsertCommand = cmdInsert
Da.Fill(ds, "Customers")
Dim dr As DataRow = ds.Tables( _
"Customers").NewRow()
Dr(0) = txtCustomerID.Text
Dr(1) = txtCompanyName.Text
Dr(2) = txtContactName.Text
Ds.Tables("Customers").Rows.Add(dr)
Da.Update(ds, "Customers")
lblResults.Text = "Row added!"
End If
End Sub

<%@ Page Language="VB" %>

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

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body bgcolor="#00ffcc">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtCustomerID" runat="server" Style="z-index:
100; left: 256px; position: absolute;
top: 240px" BorderStyle="Ridge"></asp:TextBox>
<asp:TextBox ID="txtCompanyName" runat="server" Style="z-
index: 101; left: 256px; position: absolute;
top: 272px"></asp:TextBox>
<asp:Button ID="btnAdd" runat="server" Style="z-index: 102;
left: 344px; position: absolute;
top: 360px" Text="Add" Width="128px"
OnClick="btnAdd_Click" />
<asp:TextBox ID="txtContactName" runat="server" Style="z-
index: 103; left: 256px;
position: absolute; top: 304px"></asp:TextBox>
<asp:Label ID="Label1" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 104; left: 104px; position: absolute; top:
240px" Text="Customer ID"
Width="120px"></asp:Label>
<asp:Label ID="Label2" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 105; left: 104px; position: absolute; top:
304px" Text="Contact Name"
Width="120px"></asp:Label>
<asp:Label ID="Label3" runat="server" BackColor="#004040" Font-
Bold="True" ForeColor="White"
Style="z-index: 106; left: 104px; position: absolute; top:
272px" Text="Company Name"
Width="120px"></asp:Label>
<asp:Label ID="Label4" runat="server" BackColor="White"
ForeColor="Black" Style="z-index: 108;
left: 88px; position: absolute; top: 432px"
Text="[lblResults]" Width="440px"></asp:Label>

</div>
</form>
</body>
</html>
May 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
5
by: Sky | last post by:
What makes something a valid DataSource? What methods/iterators/etc? Why do I ask? I do understand that a DataSet is based on an XML structure...but it's too table structured for what I am...
5
by: | last post by:
Trying to learn about manipulating collections of objects, and populating these objects dynamically from datasources. Could someone post a code sample that shows the following: Instantiating a...
4
by: Stephen | last post by:
IN VB.NET I have a form with a ListBox and would like to set the DataSource property at design-time but I can't seem to declare any kind of variable that will show up in the list. I have tried a...
7
by: bernadou | last post by:
How do I (or is this even possible) get the total number of records from a datasource control in ASP.NET 2.0? I’ve messed around with getting the row count from the grid that the datasource is...
2
by: H5N1 | last post by:
Hi there First of all excuse me posting such simple (I guess) question, but I didn't find the answer in tutorials. I have a formView presenting records from some table. one of the fields is...
1
by: AJ | last post by:
Hi all, I am trying pass a value to the DataSource method in a DataList like below. DataSource = <%# GetData(DataBinder.Eval(Container.DataItem, "ID"))%>" I get an error with this code, and am...
7
by: ThunderMusic | last post by:
Hi, This question probably went back a couple of times, but I didn't find anything about it on google, so I ask here... What is the best way to use the DataSource/DataBind pattern in a class? I...
1
by: WhiteWizard | last post by:
First my apologies, this may be longer than the normal question. I have a windows app (.NET 2.0, VS2005), and I've written a user control that will allow the user to "drag and drop" a directory...
9
pod
by: pod | last post by:
Hello I have a form which contains several textboxes and comboboxes I am able to loop through all the controls on this form and set the value (ctl.Text) to the Textboxes but if I try to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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

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