Showing posts with label playing. Show all posts
Showing posts with label playing. Show all posts

Monday, March 26, 2012

Newbie DataTable question

Stupid question for the day,

Just playing around with rewriting my website in .Net, I want to add a
record to my database table, in the old ADO, it was simple you could
create a connection and recordset and then rs.AddNew etc... in .Net it
seems they recommend that you populate a DataTable then use the
NewRow method

Isnt this bringing back a entire copy of the table (in this case 40,000
users), if so isn't this very inefficient? I know you can run a
insert via a ExecuteNonQuery which is the way I have done it in the
past (usually passing parameters to stored procs)

But I would have thought you should be able to add a row (Datarow) in
this case to a table without returning the entire table when you
connect to it.

Probably being very stupid

heres my code

try
{
// Initializations
string database = "MyDB.mdb";
string connectionString =
@dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
database;

//connection
OleDbConnection cnn = new OleDbConnection();
cnn.ConnectionString = connectionString;
cnn.Open();

OleDbCommand com = cnn.CreateCommand();
com.CommandText = "Select * from tblUser";

OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = com;

//DataSet ds = new DataSet();
//da.Fill(ds, "Users");

DataTable dt = new DataTable();
da.Fill(dt);

//DataRow dr = dt.Rows[0];
DataRow dr = dt.NewRow();

dr["FirstName"] = FirstName.ToString();
dr["Surname"] = Surname.ToString();
dr["Email"] = Email.ToString();

dt.Rows.Add(dr);
da.Update(dt);

//close up

cnn.Close();
}
catch (OleDbException ee)
{
Console.WriteLine(ee.ToString());
}the notion of in-memory datasets, is you only keep a copy of what you need.
the premise is that normally you only need a subset of the data. a dataset
keeps track of the status of a row (new, modified,deleted,unchanged). then
the adapter can look at the row status to determine whether to insert,
delete, update, or do nothing.

in your case you are loading the dataset solely to get the structure. you
could use the folowwing statement.

com.CommandText = "Select * from tblUser where 1 = 0";

which would only return column info and no data. a better approach is to use
typed datasets. here you use a wizard to build a dataset class that initials
the table and column info. this removes the requirement to do a dummy
database select. also you get a dot notion for accessing column data.

-- bruce (sqlwork.com)

"Ben" <BenScott@.aemail4u.com> wrote in message
news:1151423636.132121.107680@.75g2000cwc.googlegro ups.com...
> Stupid question for the day,
>
> Just playing around with rewriting my website in .Net, I want to add a
> record to my database table, in the old ADO, it was simple you could
> create a connection and recordset and then rs.AddNew etc... in .Net it
> seems they recommend that you populate a DataTable then use the
> NewRow method
>
> Isnt this bringing back a entire copy of the table (in this case 40,000
> users), if so isn't this very inefficient? I know you can run a
> insert via a ExecuteNonQuery which is the way I have done it in the
> past (usually passing parameters to stored procs)
>
> But I would have thought you should be able to add a row (Datarow) in
> this case to a table without returning the entire table when you
> connect to it.
>
> Probably being very stupid
> heres my code
> try
> {
> // Initializations
> string database = "MyDB.mdb";
> string connectionString =
> @."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
> database;
> //connection
> OleDbConnection cnn = new OleDbConnection();
> cnn.ConnectionString = connectionString;
> cnn.Open();
> OleDbCommand com = cnn.CreateCommand();
> com.CommandText = "Select * from tblUser";
> OleDbDataAdapter da = new OleDbDataAdapter();
> da.SelectCommand = com;
> //DataSet ds = new DataSet();
> //da.Fill(ds, "Users");
> DataTable dt = new DataTable();
> da.Fill(dt);
> //DataRow dr = dt.Rows[0];
> DataRow dr = dt.NewRow();
> dr["FirstName"] = FirstName.ToString();
> dr["Surname"] = Surname.ToString();
> dr["Email"] = Email.ToString();
> dt.Rows.Add(dr);
> da.Update(dt);
> //close up
> cnn.Close();
> }
> catch (OleDbException ee)
> {
> Console.WriteLine(ee.ToString());
> }
thanks Bruce,

yeah as you where writing i had tried that, bit quicker, but then it
wont allow me to insert data

"Update requires a valid InsertCommand when passed DataRow collection
with new rows."

so i guess i need to change

da.SelectCommand = com;

to

da.InsertCommand = com;

that doesnt work :(. any more words of wisdom? the main reason i am
doing this is to avoid having to handle what data is being put into
each field when the users submit the data. creating a Insert string
seem to me the wrong way to do this.

Newbie DataTable question

Stupid question for the day,
Just playing around with rewriting my website in .Net, I want to add a
record to my database table, in the old ADO, it was simple you could
create a connection and recordset and then rs.AddNew etc... in .Net it
seems they recommend that you populate a DataTable then use the
NewRow method
Isnt this bringing back a entire copy of the table (in this case 40,000
users), if so isn't this very inefficient? I know you can run a
insert via a ExecuteNonQuery which is the way I have done it in the
past (usually passing parameters to stored procs)
But I would have thought you should be able to add a row (Datarow) in
this case to a table without returning the entire table when you
connect to it.
Probably being very stupid
heres my code
try
{
// Initializations
string database = "MyDB.mdb";
string connectionString =
@dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
database;
//connection
OleDbConnection cnn = new OleDbConnection();
cnn.ConnectionString = connectionString;
cnn.Open();
OleDbCommand com = cnn.CreateCommand();
com.CommandText = "Select * from tblUser";
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = com;
//DataSet ds = new DataSet();
//da.Fill(ds, "Users");
DataTable dt = new DataTable();
da.Fill(dt);
//DataRow dr = dt.Rows[0];
DataRow dr = dt.NewRow();
dr["FirstName"] = FirstName.ToString();
dr["Surname"] = Surname.ToString();
dr["Email"] = Email.ToString();
dt.Rows.Add(dr);
da.Update(dt);
//close up
cnn.Close();
}
catch (OleDbException ee)
{
Console.WriteLine(ee.ToString());
}the notion of in-memory datasets, is you only keep a copy of what you need.
the premise is that normally you only need a subset of the data. a dataset
keeps track of the status of a row (new, modified,deleted,unchanged). then
the adapter can look at the row status to determine whether to insert,
delete, update, or do nothing.
in your case you are loading the dataset solely to get the structure. you
could use the folowwing statement.
com.CommandText = "Select * from tblUser where 1 = 0";
which would only return column info and no data. a better approach is to use
typed datasets. here you use a wizard to build a dataset class that initials
the table and column info. this removes the requirement to do a dummy
database select. also you get a dot notion for accessing column data.
-- bruce (sqlwork.com)
"Ben" <BenScott@.aemail4u.com> wrote in message
news:1151423636.132121.107680@.75g2000cwc.googlegroups.com...
> Stupid question for the day,
>
> Just playing around with rewriting my website in .Net, I want to add a
> record to my database table, in the old ADO, it was simple you could
> create a connection and recordset and then rs.AddNew etc... in .Net it
> seems they recommend that you populate a DataTable then use the
> NewRow method
>
> Isnt this bringing back a entire copy of the table (in this case 40,000
> users), if so isn't this very inefficient? I know you can run a
> insert via a ExecuteNonQuery which is the way I have done it in the
> past (usually passing parameters to stored procs)
>
> But I would have thought you should be able to add a row (Datarow) in
> this case to a table without returning the entire table when you
> connect to it.
>
> Probably being very stupid
> heres my code
> try
> {
> // Initializations
> string database = "MyDB.mdb";
> string connectionString =
> @."Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Z:\Web\Database\" +
> database;
> //connection
> OleDbConnection cnn = new OleDbConnection();
> cnn.ConnectionString = connectionString;
> cnn.Open();
> OleDbCommand com = cnn.CreateCommand();
> com.CommandText = "Select * from tblUser";
> OleDbDataAdapter da = new OleDbDataAdapter();
> da.SelectCommand = com;
> //DataSet ds = new DataSet();
> //da.Fill(ds, "Users");
> DataTable dt = new DataTable();
> da.Fill(dt);
> //DataRow dr = dt.Rows[0];
> DataRow dr = dt.NewRow();
> dr["FirstName"] = FirstName.ToString();
> dr["Surname"] = Surname.ToString();
> dr["Email"] = Email.ToString();
> dt.Rows.Add(dr);
> da.Update(dt);
> //close up
> cnn.Close();
> }
> catch (OleDbException ee)
> {
> Console.WriteLine(ee.ToString());
> }
>
thanks Bruce,
yeah as you where writing i had tried that, bit quicker, but then it
wont allow me to insert data
"Update requires a valid InsertCommand when passed DataRow collection
with new rows."
so i guess i need to change
da.SelectCommand = com;
to
da.InsertCommand = com;
that doesnt work :(. any more words of wisdom? the main reason i am
doing this is to avoid having to handle what data is being put into
each field when the users submit the data. creating a Insert string
seem to me the wrong way to do this.

Thursday, March 22, 2012

newbie hyperlink question

Hi,

Just playing around using the QuickStart site. I placed this code in my code
behind:

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub

this code in my page:

<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>

The tutorial has me placing the sub in the page itself -- but shouldn't this
work regardless? It displays the text as a link but hovering over it does
nothing.

thanksDo you want the link to go to another page..
What do you want it to do when you hover over it?
Patrick

"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hi,
>
Just playing around using the QuickStart site. I placed this code in my


code

Quote:

Originally Posted by

behind:
>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub
>
this code in my page:
>
<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>
The tutorial has me placing the sub in the page itself -- but shouldn't


this

Quote:

Originally Posted by

work regardless? It displays the text as a link but hovering over it does
nothing.
>
thanks
>
>
>
>
>
>
>


Instead of "~" try "~/" for the navigateurl.

--

Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hi,
>
Just playing around using the QuickStart site. I placed this code in my
code behind:
>
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Set hyperlink to "~", which indicates application root.
link1.NavigateUrl = "~"
End Sub
>
this code in my page:
>
<asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>
The tutorial has me placing the sub in the page itself -- but shouldn't
this work regardless? It displays the text as a link but hovering over it
does nothing.
>
thanks
>
>
>
>
>
>
>


thanks.

I originally had the file name -- "default.aspx" as the target -- and a file
by that name in the same directory -- but still the link would not activate
on viewing the page -- the style sheet viewed it as a link and applied the
appropiate style but no link functionality upon hovering over it. I have to
run but will try your suggestion first thing in the morn.

thanks for the response.

"Mark Fitzpatrick" <markfitz@.fitzme.comwrote in message
news:u1HAHXtKHHA.4912@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Instead of "~" try "~/" for the navigateurl.
>
>
--
>
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
>
>
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Hi,
>>
>Just playing around using the QuickStart site. I placed this code in my
>code behind:
>>
> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
> ' Set hyperlink to "~", which indicates application root.
> link1.NavigateUrl = "~"
> End Sub
>>
>this code in my page:
>>
><asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>>
>The tutorial has me placing the sub in the page itself -- but shouldn't
>this work regardless? It displays the text as a link but hovering over it
>does nothing.
>>
>thanks
>>
>>
>>
>>
>>
>>
>>


>
>


Thanks Patrick.

Well, when I hover over it I expected my cursor to change to a hand pointing
cursor and respond as if it were a regular html link and thus allow me to
click and follow the url assigned to it. It does neither. The style sheet
treats it as a link and formats it accordingly. But hovering over it, the
response is the same as hovering over any non-link text.

I have changed the link1,NavigateURL to "default.aspx" with a file so named
in the same directory as the page. I have changed it to "~/" as per another
suggestion made on this thread. And no go.

So I am missing something fairly fundamental. Any ideas. I took this stuff
right off the asp.net tutorial.

"Patrick.O.Ige" <naijacoder@.hotmail.comwrote in message
news:eYk9uStKHHA.5000@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Do you want the link to go to another page..
What do you want it to do when you hover over it?
Patrick
>
"thersitz" <thersitz@.gmail.comwrote in message
news:upGZO8sKHHA.4376@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Hi,
>>
>Just playing around using the QuickStart site. I placed this code in my


code

Quote:

Originally Posted by

>behind:
>>
> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
> ' Set hyperlink to "~", which indicates application root.
> link1.NavigateUrl = "~"
> End Sub
>>
>this code in my page:
>>
><asp:hyperlink ID="link1" runat="server">this link test</asp:hyperlink>
>>
>The tutorial has me placing the sub in the page itself -- but shouldn't


this

Quote:

Originally Posted by

>work regardless? It displays the text as a link but hovering over it does
>nothing.
>>
>thanks
>>
>>
>>
>>
>>
>>
>>


>
>