Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Monday, March 26, 2012

Please Help

I am writing a guest book for a web page that I am developing at the moment. The guest book is kept in an access database.

I can get the data out alright and display it, however the problem occurs when the user goes to add a comment.

Everything works fine. The user puts all the info in and then clicks on the submit button. It seems that it works. But when the page refreshes the data is not there.

I think there must be something wrong with the add function.

Could some one please help me out as I am at the end of my witts.

The code is below. Cheers,

Public Function Add(ByVal Author As String, ByVal Email As String, _
ByVal Homepage As String, ByVal State As String, ByVal Comment As String) As Boolean
Dim sql As String = "INSERT INTO Comments (Author, Email, Homepage, State, Comment) "
sql += "VALUES (@dotnet.itags.org.Author, @dotnet.itags.org.Email, @dotnet.itags.org.Homepage, @dotnet.itags.org.State, @dotnet.itags.org.Comment)"
' create a new OleDbCommand and set its params
Dim myCmd As OleDbCommand = New OleDbCommand(sql, _Connection)
myCmd.Parameters.Add(New OleDbParameter("@dotnet.itags.org.Author", OleDbType.VarChar, 50))
myCmd.Parameters("@dotnet.itags.org.Author").Value = Author.Trim()
myCmd.Parameters.Add(New OleDbParameter("@dotnet.itags.org.Email", OleDbType.VarChar, 50))
myCmd.Parameters("@dotnet.itags.org.Email").Value = Email.Trim()
myCmd.Parameters.Add(New OleDbParameter("@dotnet.itags.org.Homepage", OleDbType.VarChar, 100))
myCmd.Parameters("@dotnet.itags.org.Homepage").Value = Homepage.Trim()
myCmd.Parameters.Add(New OleDbParameter("@dotnet.itags.org.State", OleDbType.VarChar, 50))
myCmd.Parameters("@dotnet.itags.org.State").Value = State.Trim()
myCmd.Parameters.Add(New OleDbParameter("@dotnet.itags.org.Comment", OleDbType.VarChar))
myCmd.Parameters("@dotnet.itags.org.Comment").Value = EncodeHTMLText(Comment.Trim())
Add = True
myCmd.Connection.Open()
Try
myCmd.ExecuteNonQuery()
Catch e As OleDbException
Add = False
Finally
myCmd.Connection.Close()
End Try
End FunctionHave you tried using ? instead of @.paramname:-

Dim sql As String = "INSERT INTO Comments (Author, Email, Homepage, State, Comment) "
sql &= "VALUES (?, ?, ?, ?, ?)"
I gave up and re wrote the form using ADODB. My code is below. If any one has any ways to improve please tell me.

Thankx for your help....

Dim rs As ADODB.Recordset
rs = New ADODB.Recordset()
rs.CursorType = ADODB.CursorTypeEnum.adOpenKeyset
rs.LockType = ADODB.LockTypeEnum.adLockOptimistic
rs.Open("Comments", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\webspace\myweb.com\db\Guestbook.mdb;Persist Security Info=False;", , , ADODB.CommandTypeEnum.adCmdTable)
rs.AddNew()
rs.Fields(1).Value = Author.Text
rs.Fields(2).Value = Email.Text
rs.Fields(3).Value = Homepage.Text
rs.Fields(4).Value = State.Text
rs.Fields(5).Value = Comment.Text
rs.Update()
rs.Close()
rs = Nothing

Please Help

Let me start by saying that this is a custom shopping cart application, built using Visual Web Developer with an SQL 2005 Express database. This is my first real project so most of these things are new to me. For the most part, everything works, you can log in, navigate around and whatever, but the process of adding products to your cart and viewing your cart seems just that bit too hard.

The database has Products, Categories, Manufacturers, Customers and Orders tables (you'll find out the important fields later) and a membership provider has been implemented to store user details in the Customers table, those being Name, Password and E-Mail along with an automatically incremented ID.

An "Administration" section has been set up to allow people to create and modify the products, categories and manufacturers. This generates a menu on the left hand side which has links to "~/Details.aspx?CategoryID={0}" which brings up a page with a GridView control showing information about every item that belongs to the category specified in the QueryString. In this GridView, the important columns are ProductID (which has a Label), Quantity (which has a TextBox) and Add (which has a Button).

In order to add products to a customer's cart, we must do the following, which is where it gets too complicated for me...
- get the user's CustomerName and corresponding CustomerID and enter that in the Orders table
- get the ProductID of the appropriate row (the one where the button was clicked)
- get the value from the Quantity of the appropriate row

For example, finding the CustomerName is easy...

Dim CustomerNameAs String = Context.User.Identity.Name

...but then finding the CustomerID of that user and using it as a parameter in SQL is too hard.

My only idea as far as the ProductID and Quantity goes was to make the "Add" button select the row, then find the information from the selected row.

Answering the above problems would also solve this one, but then when the user goes to view their cart, we have to filter the data to only show the orders with their CustomerID. Again, that means finding the CustomerName, then corresponding CustomerID, then saying "WHERE (Orders.CustomerID = *insert parameter here*).

If someone could help me figure out these issues it would be much appreciated.

Thanks.

Managed to fix the issue regarding the CustomerID and CustomerName, but it's not the nicest of solutions.

Dim UserAs String = Context.User.Identity.NameCustomerName.Text = User
Just takes a hidden TextBox, assigns it the value of the user's name and that's used as a ControlParameter. But, as above, there should be a cleaner way of doing this and besides, it only helps with the "View Cart" page, not adding items to your cart. This is because of the following clause in the SQL...

WHERE (Customers.CustomerName = @.CustomerName AND Orders.CustomerID = Customers.CustomerID)

...but the corresponding CustomerID is still needed for adding products.

Can somebody please help me out here?


It seems a "INSERT INTO...SELECT" statement is required, we're reading up on it at the moment and trying to get it working, but some assistance would still be welcome.

For example, what is the syntax for using "INSERT INTO...SELECT" to get values from another table, while also using parameters from the page in the same statement, something like this?

INSERT INTO Orders (CustomerID, ProductID, Quantity) VALUES ("SELECT CustomerID FROM Customers WHERE CustomerName = @.CustomerName", @.ProductID, @.Quantity)

Obviously, that's the wrong syntax, but it should help to understand what we're trying to do.


Made some progress here, managing to figure out the correct SQL statement (which is below if you're interested).

The problem is, we must use controls from the corresponding row of the GridView, according to which "Add" button was clicked. To do this, we thought it would be easy to just select the row and use GridView.Rows(GridView.SelectedIndex).FindControl and to an extent that works. However, with CommandName="Select" and OnClick="Add", the latter is fired first, which means that the row is not selected.

How can we get the row to be selected before the OnClick event is triggered?

Thanks.

"INSERT INTO [Orders] ([CustomerID], [ProductID], [Quantity]) SELECT [CustomerID], @.ProductID, @.Quantity FROM [Customers] WHERE ([CustomerName] = @.User)"

please help

error message
=============
Microsoft JET Database Engine- Error '80040e14'

Syntax error (comma) in query expression 'id=67, 68'.

C:\sambar60-1\home\kenny\manage\userdelete.asp, line 105

cn.execute(sql)

=====================================================

member.asp
===========
<!--#include file="cnndb.asp"-->
<%
set rs=server.createobject("ADODB.Recordset")
sql="select * from Users order by userNo"
rs.open sql,cn,1,1
%
<html>
<head>
<title>MEMBER</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
td {
font-family: "Verdana";
font-size: 14px;
color: #000000;
text-decoration: none;
}
body {
font-family: "Verdana";
font-size: 14px;
color: #000000;
text-decoration: none;
}
-->
</style>
<script languagge="javascript">
function checkdata(){

if (document.form1.userno.value==""){
alert("PLEASE INSERT USER NO");
document.form1.userno.focus();
return false;
}

document.form1.submit();
}
function confirmdel1(filename){
if (!confirm("CONFIRM DELETE ("+filename+")?"))
{return false;
}
return true;
}
function confirmdel2(filename){
if (!confirm("CONFIRM SUSPEND ("+filename+")?"))
{return false;
}
return true;
}
function confirmedit(filename){
if (!confirm("CONFIRL EDIT ("+filename+")?"))
{return false;
}
return true;
}

function deleteRec()
{

if(confirm("CONFIRM DELETE?"))
{

document.form1.action="userdelete.asp";
document.form1.submit();
}
}

function suspentRec()
{

if(confirm("CONFIRM SUSPENT?"))
{

document.form1.action="userstop.asp";
document.form1.submit();
}
}

function resetRec()
{

if(confirm("CONFIRM RESET?"))
{

document.form1.action="userstatus.asp";
document.form1.submit();
}
}

function editRec()
{

if(confirm("CONFIRM Edit?"))
{

document.form1.action="useredit.asp";
document.form1.submit();
}
}

</script>
<style type="text/css">
<!--
a {
font-family: "Verdana";
font-size: 14px;
color: #0000FF;
text-decoration: underline;
}
a:hover {
font-family: "Verdana";
font-size: 14px;
color: #FF3300;
text-decoration: underline;
}
--
</style>
</head
<body bgcolor="#FFD21E"
<div align="center">
<form name="deleteform" method="post" action="userdelete.asp">
<table width="467" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#000000" width="469">
<table width="469" border="0" cellspacing="1" cellpadding="0">
<tr align=center>
<td height="25" colspan="5" bgcolor="#CC0033" width="467"><font color="#FFFFFF" size="3">MEMBER
LISTINGS
<input type="button" name="Button2" onClick="document.location='member.asp'" value=" REFRESH " style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 20px">
</font></td>
</tr>
<tr align=center bgcolor="#000099">
<td width="99" height="20"><font color="#FFFFFF">USR</font></td>
<td width="99" height="20"><font color="#FFFFFF">PWD</font></td>
<td width="148" height="20"><font color="#FFFFFF">REMARKS</font></td>
<td width="50" height="5"><font color="#FFFFFF">SET</font></td>
<td width="67" height="20"></td>
</tr><% do while not rs.eof %>
<tr>
<td height="10" align="center" bgcolor="#F5f5f5" width="99"><font color="#0000FF"><%=rs("userNo")%></font></td>
<td height="10" align="center" bgcolor="#F5f5f5" width="99"><font color="#0000FF"><%=rs("ballpassword")%></font></td>
<td height="10" align="center" bgcolor="#F5f5f5" width="148"><font color="#0000FF"><%=rs("meno")%></font></td
<td align="center" valign="top" width="50" bgcolor="#F5f5f5"><input type="checkbox" name="deleted" value="<%=trim(rs("id"))%>"><%=trim(rs("id"))%
</font>
</td>
<td height="10" bgcolor="#F5f5f5" width="67"><div align="center"><font color="#ff0000">
<%
if trim(rs("pause"))="0" and trim(rs("status"))="0" then
response.write"<font color=black>OFF</font color>"
elseif trim(rs("pause"))="1" and trim(rs("status"))="0" then
response.write"SUSPENDED"
elseif trim(rs("pause"))="0" and trim(rs("status"))="1" then
response.write"ON"
elseif trim(rs("pause"))="1" and trim(rs("status"))="1" then
response.write"STOPPED"
else
response.write"ERROR"
end if
%>
</font></div></td>
</tr><% rs.movenext
if rs.eof then
exit do
end if
%>
<tr>
<td height="10" align="center" bgcolor="#FFFFD9" width="99"><font color="#0000FF"><%=rs("userNo")%></font></td>
<td height="10" align="center" bgcolor="#FFFFD9" width="99"><font color="#0000FF"><%=rs("ballpassword")%></font></td>
<td height="10" align="center" bgcolor="#FFFFD9" width="148"><font color="#0000FF"><%=rs("meno")%></font></td>
<td align="center" valign="top" width="50" bgcolor="#FFFFD9"><input type="checkbox" name="deleted" value="<%=trim(rs("id"))%>"><%=trim(rs("id"))%
</font></td>
<td height="10" bgcolor="#FFFFD9" width="67"><div align="center"><font color="#ff0000">
<% if trim(rs("pause"))="0" and trim(rs("status"))="0" then
response.write"<font color=black>OFF</font color>"
elseif trim(rs("pause"))="1" and trim(rs("status"))="0" then
response.write"SUSPENDED"
elseif trim(rs("pause"))="0" and trim(rs("status"))="1" then
response.write"ON"
elseif trim(rs("pause"))="1" and trim(rs("status"))="1" then
response.write"STOPPED"
else
response.write"ERROR"
end if
%>
</font></div></td>
</tr><% rs.movenext
if rs.eof then
exit do
end if
loop
%>
</table></td>
</tr>
</table>
<td align="right" colspan=13 bgcolor="#FFE1AD">
<input type="submit" value="Delete">
<input type="button" name=updateButton onClick="suspentRec()" value="Suspent">
<input type="button" name=resetButton onClick="resetRec()" value=" Reset ">
<input type="button" name=EditButton onClick="editRec()" value=" Edit "></form>
<br><form name="form1" method="post" action="testing.asp">
<table width=200 border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#99CC33">
<table height="109" border="0" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFD0">
<td height="20" colspan="2" width="214">
<p align="center"><font color="#FF0000" size="3">ADD NEW MEMBER</font></td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77" bgcolor="#FFFFD0">USER:</td>
<td width="130">
<input name="userno" type="text" id="userno" maxlength="20" size="17"> </td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">PWD:</td>
<td width="130">
<input name="password" type="password" id="password" maxlength="20" size="17"> </td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">REMARKS:</td>
<td width="130">
<input name="meno" type="text" id="meno" maxlength="100" size="17"></td>
</tr>
<tr bgcolor="#FFFFD0">
<td width="77">TEL:</td>
<td width="130">
<input name="tel" type="text" id="tel" maxlength="100" size="17"></td>
</tr>
<tr bgcolor="#FFFFD0" align=center>
<td height="50" bgcolor="#FFFFD0" colspan=2><input type="button" name="Button" onClick="checkdata()" value="ENTER" style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 30px">
<input type="button" name="Button3" onClick="javascript:document.location='updateadmin.asp'" value="CHANGE PWD" style="FONT-SIZE: 12px; FONT-FAMILY: VERDANA; HEIGHT: 30px"></td>
</tr>
</table></td>
</tr>
</table>
</form></div>
<br>
<% rs.close
set rs=nothing
closeCN
%>
</body>
</html>
==========================================================

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id="&request("deleted")&""
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
=========================================================

please help me how can i query/loop the id so that it will delete the record 1 by 1?
ThanksCan you resume to the code related to the question only.
the code is only on userdelete.asp

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if Request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id="&Request("deleted")&""
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
========================================

error
====
Microsoft JET Database Engine- Error '80040e14'

Syntax error (comma) in query expression 'id=66, 67'.

C:\sambar60-1\home\kenny\manage\userdelete.asp, line 105

cn.execute(sql)

===========================================

if i only selected 1 record to delete in checkbox, the program will delete. But more than 1 ID, the program will error above.
You can not delete multiple records like that.

It does not like the id=66, 67. You need to do something like:

id IN (66, 67)
so how to fix the code?
i'm really stuck in this error for few days already.
Please help me...
Use namespace System.Text.RegularExpressions
Try out something as


Dim strValues As String = "67,68"
Dim FieldsValues() As String = Regex.Split(strValues, ",")
Dim x As String
For Each x In FieldsValues
'Put delete code here
Next


In userdelete.asp you have:

sql="delete * from Users where id="&Request("deleted")&""

Replace it with:

sql="delete * from Users where id IN (" & Request("deleted") & ")"

This way, if there is just one record it will still work, but if there are multiple selected it should handle them as well.
yes!!!! that's work....
much much thanks for your help mbradford
:)
mbradford, did you know how to code a soccer predictions competition program using asp?
:)
nope, just a lucky guess ;-)
mbradford, i facing a new problem now.

actually i have 4 function button after display records which is (Delete, Suspent, Reset, Edit).
justnow what you teach me is i'm using a form format (action="userdelete.asp"), but now how can i click the delete button it goes to userdelete.asp and when i click edit it goes to useredit.asp? and how to let my program carry out the ID together to the *.asp page?

i have some javascript code in my program,
=================================

document.form1.submit();
}
function confirmdel1(filename){
if (!confirm("CONFIRM DELETE ("+filename+")?"))
{return false;
}
return true;
}
function confirmdel2(filename){
if (!confirm("CONFIRM SUSPEND ("+filename+")?"))
{return false;
}
return true;
}
function confirmedit(filename){
if (!confirm("CONFIRL EDIT ("+filename+")?"))
{return false;
}
return true;
}

function deleteRec()
{

if(confirm("CONFIRM DELETE?"))
{

document.form1.action="userdelete.asp";
document.form1.submit();
}
}

function suspentRec()
{

if(confirm("CONFIRM SUSPENT?"))
{

document.form1.action="userstop.asp";
document.form1.submit();
}
}

function resetRec()
{

if(confirm("CONFIRM RESET?"))
{

document.form1.action="userstatus.asp";
document.form1.submit();
}
}

function editRec()
{

if(confirm("CONFIRM Edit?"))
{

document.form1.action="useredit.asp";
document.form1.submit();
}
}
===================================================

<input type="button" name=DeleteButton onClick="deleteRec()" value="Delete">
<input type="button" name=UpdateButton onClick="updateRec()" value="Suspent">
<input type="button" name=ResetButton onClick="resetRec()" value=" Reset ">
<input type="button" name=EditButton onClick="editRec()" value=" Edit "
This is the button which after listing all my records.
====================================================
In your form tag you currently have:

<form name="deleteform" method="post" action="userdelete.asp"
Try taking off:

action="userdelete.asp"

and then your javascript should take care of the submit
i have remove the action tag but the program still can't do any job i request. how now?
or i put the action tag (action="useraction.asp") new .asp page, and join all the code in userdelete.asp, userstatus.asp and userstop.asp?

how to join together so that when submit the button the program will know if it is delete button then goes to deleteuser code, suspent button then goes to userstop.asp?

can you give me some idea should i use javascript or merge these 3 files code together and how to merge?

userdelete.asp
==========
<!--#include file="cnndb.asp"-->
<%
if Request("deleted")="" then
response.redirect"member.asp"
end if
sql="delete * from Users where id IN ("&Request("deleted")&")"
cn.execute(sql)
closeCN
%><script
javascript:document.location='member.asp';
</script>
====================================================

userstatus.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("id")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause,status from Users where id="&request("id")&""
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="0"
rs("status")="0"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script>
====================================

userstop.asp
==========
<!--#include file="cnndb.asp"-->
<%
if request("id")="" then
response.redirect"member.asp"
end if
set rs=server.createobject("ADODB.Recordset")
sql="select pause from Users where id="&request("id")&""
rs.open sql,cn,1,2
if not rs.eof then
rs("pause")="1"
rs.update
end if
rs.close
set rs=nothing
closeCN
%><script
javascript:document.location='member.asp';
</script>
================================================

if using javascript, what should i do now? do you need the member.asp code?

Please Help - Allow Paging on Grid Properties Builder

Hi,

I'm working on a grid when the database returns ... say 100 rows. I would
like to use the Allow Page in the grid Properties, but don't really know how
to code it right. I copied some code from the help, but it doesn't really
work yet. The compiler complains on the following...

private void InitializeComponent()
{
this.gridLegalEntityEmployee.SelectedIndexChanged += new
System.EventHandler(this.gridLegalEntityEmployee_S electedIndexChanged);
this.gridLegalEntityEmployee.PageIndexChanged += new
System.EventHandler(this.gridLegalEntityEmployee_P ageIndexChanged );

this.Load += new System.EventHandler(this.Page_Load);

}

private void gridLegalEntityEmployee_PageIndexChanged( object source,
System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
{
gridLegalEntityEmployee.CurrentPageIndex = e.NewPageIndex;
gridLegalEntityEmployee.DataBind();
}

=== Error ======
this.gridLegalEntityEmployee_PageIndexChanged =>
'cpNET.WebForm1.gridLegalEntityEmployee_PageIndexC hanged(object,
System.Web.UI.WebControls.DataGridPageChangedEvent Args)' does not match
delegate 'void System.EventHandler(object, System.EventArgs)'

Here is some other sniplet code

================================================== ==============
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
gridLegalEntityEmployee.AllowPaging = true;
gridLegalEntityEmployee.PagerStyle.Mode = PagerMode.NumericPages;
gridLegalEntityEmployee.PagerStyle.PageButtonCount = 15;
gridLegalEntityEmployee.PageSize = 15;

LoadLegalEntityEmployeeList();

if (!Page.IsPostBack)
{
gridLegalEntityEmployee.DataBind();
}
}

private void LoadLegalEntityEmployeeList()
{
LegalEntityEmployee leEmployee = new LegalEntityEmployee();

// Retrieve data from database
gridLegalEntityEmployee.DataSource = leEmployee.SelectAll();

// Bind it to Databind
gridLegalEntityEmployee.DataBind();
}
================================================== ==============

I know there is a stupid mistake I made here, but I just cant't see it. Any
suggestion or recommeded is greatly appreciated. I really appriciate you
guys help.

Thanks a lot.

Eddyyou page index changed event is mapped to the wrong handler
it should be
System.Web.UI.WebControls.DataGridPageChangedEvent Handler instead of
system.eventhandler

"Eddy Soeparmin" <esoeparmin@.clientprofiles.com> wrote in message
news:OyTwWzjSDHA.940@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I'm working on a grid when the database returns ... say 100 rows. I would
> like to use the Allow Page in the grid Properties, but don't really know
how
> to code it right. I copied some code from the help, but it doesn't really
> work yet. The compiler complains on the following...
> private void InitializeComponent()
> {
> this.gridLegalEntityEmployee.SelectedIndexChanged += new
> System.EventHandler(this.gridLegalEntityEmployee_S electedIndexChanged);
> this.gridLegalEntityEmployee.PageIndexChanged += new
> System.EventHandler(this.gridLegalEntityEmployee_P ageIndexChanged );
> this.Load += new System.EventHandler(this.Page_Load);
> }
> private void gridLegalEntityEmployee_PageIndexChanged( object source,
> System.Web.UI.WebControls.DataGridPageChangedEvent Args e)
> {
> gridLegalEntityEmployee.CurrentPageIndex = e.NewPageIndex;
> gridLegalEntityEmployee.DataBind();
> }
> === Error ======
> this.gridLegalEntityEmployee_PageIndexChanged =>
> 'cpNET.WebForm1.gridLegalEntityEmployee_PageIndexC hanged(object,
> System.Web.UI.WebControls.DataGridPageChangedEvent Args)' does not match
> delegate 'void System.EventHandler(object, System.EventArgs)'
> Here is some other sniplet code
> ================================================== ==============
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> gridLegalEntityEmployee.AllowPaging = true;
> gridLegalEntityEmployee.PagerStyle.Mode = PagerMode.NumericPages;
> gridLegalEntityEmployee.PagerStyle.PageButtonCount = 15;
> gridLegalEntityEmployee.PageSize = 15;
> LoadLegalEntityEmployeeList();
> if (!Page.IsPostBack)
> {
> gridLegalEntityEmployee.DataBind();
> }
> }
> private void LoadLegalEntityEmployeeList()
> {
> LegalEntityEmployee leEmployee = new LegalEntityEmployee();
> // Retrieve data from database
> gridLegalEntityEmployee.DataSource = leEmployee.SelectAll();
> // Bind it to Databind
> gridLegalEntityEmployee.DataBind();
> }
> ================================================== ==============
> I know there is a stupid mistake I made here, but I just cant't see it.
Any
> suggestion or recommeded is greatly appreciated. I really appriciate you
> guys help.
> Thanks a lot.
> Eddy

Saturday, March 24, 2012

Please help ! Server Error in Application ! Object variabl

Hi Roger,
I havent solved my problem yet.
I was wondering if it has something to do with database locks. I checked for
any locks, but couldnt find any at the time of the error.
I have no idea how to solve this problem.
Please let me know if you come across any solutions.
Thanks
majo
"rogercnorris@dotnet.itags.org.yahoo.com" wrote:

> Did you ever resolve this issue? I'm currently experiencing something
> similar. An ASP.NET application was running fine on a Windows XP
> machine. But now that we've moved it to Windows Server 2003, it
> *sometimes* gets the error that you described:
> System.NullReferenceException: Object variable or With block variable
> not set.
> at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object
> o, Type objType, String name, Object[] args, String[] paramnames,
> Boolean[] CopyBack)
> This is while accessing a COM object. Once again, it's worked
> flawlessly on XP for quite a while now, but seems to occasionally have
> problems on Windows Server 2003 (maybe the operating system isn't the
> main issue, but I don't know what other differences exist).
> - Roger
>Hi,
This time, I got a new Server Error
"Fill: selectcommand.connection property has not been initialized" in
another asp page. This also comes only ONCE IN A WHILE.
The error is coming in the line with "Fill" in the code given below
*--
DBConnection = OnlineConn.OnlineDBConnection(Database)
Sql = KeyWord
Dim SqlCommand As New SqlCommand(Sql, DBConnection)
Dim SqlAdapter As New SqlDataAdapter(SqlCommand)
Dim DataSet As New DataSet
SqlAdapter.Fill(DataSet)
*--
While linking this with my previous error " Object variable with block ... "
, I was wondering if this error has anything to do with the database
connection.
Will this happen if the asp.net page is refreshed frequently ?
Thanks in advance for your help
Rgds,
Majo
"majo" wrote:
> Hi Roger,
> I havent solved my problem yet.
> I was wondering if it has something to do with database locks. I checked f
or
> any locks, but couldnt find any at the time of the error.
> I have no idea how to solve this problem.
> Please let me know if you come across any solutions.
> Thanks
> majo
>
> "rogercnorris@.yahoo.com" wrote:
>
Hi,
I created a new virtual directory in IIS and xcopied the whole content
(which is giving me the server error)
Right at the moment when i got the server error in my initial application, i
tried the new application which was created by me and it WORKED WELL.
Does this mean, that this server error has nothing to do with database locks
or IIS ?
I think, it has something to do with concurrent connections.
Can anyone help me with the connection parameters which i should use.
Many thanks...

Please help Friends how to control maxlength textbox in datagrid

Is there a way to set the maxlength property for a text box in the datagrid.

My database table field size is only 10 chars for first name.

How can i make the user not to enter more tha 10 chars on the front end.

Is there any Max length property i can assign for the text boxes.

I have 4 text boxes in datagrid.

Thank you very much.Hi,

if it is single-line TextBox, you can use its MaxLength property like you normally can.

<asp:TextBox ID="xxx" MaxLength="4"... /
This works even if TextBox is in a DataGrid.
Thanks Joteke, I have the following code triggered when i click edit in the datagrid, then it will show all text boxes etc. where can i place the maxlength="4" property in the following code.

Thank you very much.

< Code >
Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs )
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim strConn as string = "server=Rajender;uid=sa;pwd=sa;database=NORTHWIND"
Dim txtFirstName As textbox = E.Item.cells(2).Controls(0)
Dim txtLastName As textbox = E.Item.cells(3).Controls(0)
Dim txtTitle As textbox = E.Item.cells(4).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt =" UPDATE Employees SET" & _
" FirstName =@.Fname, LastName =@.Lname, Title = @.Title " & _
" WHERE EmployeeID = @.EmpID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SQLParameter("@.Fname", txtFirstName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Lname", txtLastName.text))
MyCommand.Parameters.Add(New SQLParameter("@.Title", txtTitle.text))
MyCommand.Parameters.Add(New SQLParameter("@.EmpID", e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub

</ code >
In that case, you could declare EditItemTemplate for the DataGrid (declaratively in asox) in which you set the TextBox's MaxLength.

If you want to do it programmatically, then you'd do it in ItemDataBound method (when ItemType is EditItem)

Wednesday, March 21, 2012

please help i need help urgently

Hi

I am working on asp.net application using vb.net as its language

I want to displaysystem date in a textbox and enter the value into sql database when a button "submit" is clicked

how can do it?when ever this webpage is started the textbox should automatically take the date in the text box and when i click a button submit that date should enter into the sql database

how can i do this?

please help i have an urgent project to be submitted on this plzzzz

You can get the current date by using System.DateTime.Now, however, I suggest you go through the video's and tutorials fromhttp://asp.net/learn to learn how to use ASP.NET before starting on any "urgent" projects.


Hi,

In the Page Load event

first check

if(!ispostback)

then

textbox.text=datetime.now.tostring()

also same for the submit button accept send the value in the insert query rather then textbox


You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in databaseYou can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.


You can also implement it in database level by using getdate()(for SQL server) function in the insert query or stored procedure whatever used by you to insert the value in database.


"please help i have an urgent project to be submitted on this plzzzz"#

sounds like homework..

please Help me find out a way!

I want a client to enter a 'key' in a textbox and click a button. then the entered value will be used to search a table in the MS-SQL database. The corresponding value found from that table will be used to search a second table. Data found from the second table will be bounded to the datagrid control at the page where the client entered the 'key'. What will be the way to achieve this? What will be the SQL command??

I'm not sure if I'm able to describe the problem. I'm a new user of ASP.NET. So please help.

Ishtiaque.

A stored procedure like this will work:

CREATE PROCEDUREdbo.Example
@.key1varchar(255)
AS
DECLARE@.key2varchar(255)
SELECT@.key2 = key2columnFROMTable1WHEREkey1column = @.key1
--The select below will return your results so you can bind to your grid:
SELECT*FROMTable2WHEREkey2column = @.key2


Thank you Sharbel_.

I made a stored procedure as you suggested and used it by a 'drag and drop' method in my webform. But as I mentioned I am a novice user of ASP.NET, could not utilize the sqlConnection or sqlCommand that resulted of doing so. Would you please let me know how to do so?

Thanks in advance.


Hi,

using System.Data.SqlClient; at the top in the .cs file

Create the connection and the command objects in the page_load or in the button click as

SqlConnection sqlcn =new SqlConnection(connectionString);

sqlcn.Open();

//creating and initialising a command object

SqlCommand sqlcm =new SqlCommand();

sqlcm.Connection = sqlcn;

sqlcm.CommandType = CommandType.StoredProcedure;

sqlcm.CommandText = StoredProcedure name;

sqlcm.ExecuteNonQuery();

HTH.

Please help me I am stuck!

I have a few question on ASP.net accessing database. Can you please help me??
The situation is like this:
There are 2 listbox, listboxA and listboxb. ListboxA contains all the available interviewer's names. Then listboxb contains the selected interviewer's name. Now I need to extract all the name from listboxb and find their corresponding ID in a table call interviewer then insert their corresponding ID to another table call performance. How am I suppose to do that? Secondly is: For example i got 2 sql statement, how do I execute them at the same time, in other words is there any codes that can insert a data into multiple tables and multiple rows to a database?
Can you please help me with it?
I am really stuck on this.here is the code:

I used button press event to insert the ID's from the listb.


if(!Page.IsPostBack)
{
SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM tblPerson",myConnection);
DataSet ds = new DataSet();
ad.Fill(ds,"tblPerson");

myBox.DataSource = ds;
myBox.DataTextField = "Name";
myBox.DataValueField = "PersonID";
myBox.DataBind();

}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.myConnection = new System.Data.SqlClient.SqlConnection();
//
// myConnection
//
this.myConnection.ConnectionString = "workstation id=GEEK;packet size=4096;integrated security=SSPI;initial catalog=DBP" +
"erson;persist security info=False";
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
foreach(ListItem l in myBox.Items)
{
SqlCommand myCommand = new SqlCommand("ADDPERSON",myConnection);
myCommand.CommandType = CommandType.StoredProcedure;

myCommand.Parameters.Add(new SqlParameter("@.p_ID",SqlDbType.Int,4));
myCommand.Parameters["@.p_ID"].Value = Convert.ToInt32(l.Value);

myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();

}
}


Thanks alot... but I don't really know how to use StoredProcedure.
Where did you initialise the "ADDPERSON" ?
Is there any website I can look up for reference?
Sorry to trouble you, but thanks alot
Creating Stored Procedures and User-Defined Functions;

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vdbt7/html/dvhowcreatingstoredprocedure.asp

Using Stored Procedures with a Command

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingstoredprocedureswithcommand.asp
Here is the stored procedure that I have used:


CREATE PROCEDURE [ADDPERSON]

@.p_ID int

AS

INSERT INTO tblDeveloper(PersonID) VALUES(@.p_ID);
GO

Please help me improve this class for accessing database data

Hi All

I've just written my first class that attempts to perform the following actions:
1. Connect to SQL Server 2000 using the connection defined in web.config
2. Execute a stored procedure (passed as a parameter) using any number of SQL parameters
3. Return the data as a dataTable back to the calling page

I need some really general advice from you experts to help improve it in the following ways if possible:
1. Reliability
2. Performance

Although it does work, it's probably quite badly written as to be honest I don't really know what I'm doing. Any help would be really appreciated! Big Smile [:D]

Namespace myNS
Public Class dataGrabber

Private Shared myConn As New SqlConnection(ConfigurationManager.ConnectionStrings("myConnString").ConnectionString)
Private Shared mySQLCommand As New SqlCommand
Private Shared myDataReader As SqlDataReader

Public Sub New(ByVal storedProcedureToRun As String)
mySQLCommand.Connection = myConn
mySQLCommand.CommandText = storedProcedureToRun
mySQLCommand.CommandType = CommandType.StoredProcedure
End Sub

Public Sub AddParam(ByVal paramName As String, ByVal paramDataType As SqlDbType, ByVal paramValue As String)
Dim tmpParam As New SqlParameter(paramName, paramDataType)
tmpParam.Value = paramValue
mySQLCommand.Parameters.Add(tmpParam)
End Sub

Public ReadOnly Property getData() As DataTable
Get
Dim myDataTable As New DataTable
mySQLCommand.Connection.Open()
myDataReader = mySQLCommand.ExecuteReader(CommandBehavior.CloseConnection)
myDataTable.Load(myDataReader)
mySQLCommand.Parameters.Clear()
mySQLCommand.Dispose()
Return myDataTable
End Get
End Property

End Class
End Namespace

With my expereince, I always make my data layers static, there is really no need to maintain class instances in the data layer, however there are exceptions depending on the requirements of your project.

In my data layers, I execute a command like so: MyDataLayer.ExecuteDataSet(cn, "SP_NAME", object[] args);

notice the last parameter is an object array that will hold the parameters for the stored proc.

If you want some good ideas and good practices, download microsofts data access application block and look through the code. They have some good code in there that uses caching for parameters and connections, which speeds up the datalayer.

Also take a look at patterns & practices on msdn. there is alot of good info on there.


You shouldn't make your class-level variables (myConn etc) shared. And if you want to return a DataTable you could use the DataAdapter rather than getting a Reader and loading it into a DataTable.
Thanks both for your help.

>> You shouldn't make your class-level variables (myConn etc) shared
I thought Shared just meant that other subs and functions in the class could access these once they had been declared. Obviously not. What is Shared therefore?

>> if you want to return a DataTable you could use the DataAdapter rather than getting a Reader and loading it into a DataTable
Could you please provide an example of this that would fit the code above?

Thanks again guys! Big Smile [:D]
Shared means there is only one instance of the object that spans all classes. So if you create two instances of your data class they both share the same connection and command object. So if one user on your site is running SPA and at the same time another user is running SPB you will get unexpected results.

For the DataAdapter;

http://authors.aspalliance.com/aspxtreme/sys/data/Common/DataAdapterClassFill.aspx


Hi Aidy
From the examples I can see online, all use a dataAdapter to fill adataTable or dataSet. Therefore (from my basic understandingWink [;)]) I'dstill require the temporary dataTable in the class to pass back to the calling page, right?? On top of this,wouldn't the dataAdapter use more resources than the dataReader?

I'm using the class in my pages as follows;

Dim DBAccess As New myNS.dataGrabber("sp_getlogin") ' instance of class
DBAccess.AddParam("username", SqlDbType.NVarChar, loginControl.UserName) ' add param username
DBAccess.AddParam("password", SqlDbType.NVarChar, loginControl.Password) ' add param password
Dim loginTable As DataTable = DBAccess.getData() ' returns values from database to use for this user

Friday, March 16, 2012

Please help me understand this PostBack Issue

I am inserting a row in a database. All that works fine. What I now
need is the last inserted id from the database. I can get that. Again
all working.
Then what I need to have is that same last inserted id key to be
available when the page reloads. When I press the button to insert the
data, I can do this:
Session("last")=LAST_ID;
Response.Write("My row id is: " + Session("last"));
//this works and is inside my INSERT button_click event
But when the Page_Load comes back I cannot see it. I try this:
if (Page.IsPostBack)
Response.Write("My row upon postback is: " + Session("last"));
//this fails upon postback in the Page_Load
It is just blank. Nothing there.
Instead of a Session variable, I have tried a static variable, (I think
ViewState, but am not sure), a global variable, nothing holds the data
upon PostBack.
Thank you for any help.And what I don't get is that when I do a trace it shows my INSERT code
in the Begin PostBack which looks like I would have access to the
variable.
I'm sorry to keep responding to myself, but it looks like the lifecycle
is as follows:
Page_Load
Button_click
So,
Page_Load fails to show a Session Variable or any other because it has
not been initialized yet.
Button_click is where the row is inserted and the last ID is given.
But because the Button_click has fired after the Page_load the
page_load never sees the value.
So I must find a way to get the last row id..oh wait..I populate the
controls after the insert in that click event instead of the Page_Load
event.
Thanks!
Umm, glad to be of assistance? :)
Mythran
needin4mation@.gmail.com wrote:

> I'm sorry to keep responding to myself, but it looks like the
> lifecycle is as follows:
> Page_Load
> Button_click
RTM...
http://msdn.microsoft.com/library/d...y/en-us/cpguide
/html/cpconControlExecutionLifecycle.asp
;-)
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Please help me understand this PostBack Issue

I am inserting a row in a database. All that works fine. What I now
need is the last inserted id from the database. I can get that. Again
all working.

Then what I need to have is that same last inserted id key to be
available when the page reloads. When I press the button to insert the
data, I can do this:

Session("last")=LAST_ID;
Response.Write("My row id is: " + Session("last"));
//this works and is inside my INSERT button_click event

But when the Page_Load comes back I cannot see it. I try this:

if (Page.IsPostBack)
Response.Write("My row upon postback is: " + Session("last"));
//this fails upon postback in the Page_Load

It is just blank. Nothing there.

Instead of a Session variable, I have tried a static variable, (I think
ViewState, but am not sure), a global variable, nothing holds the data
upon PostBack.

Thank you for any help.And what I don't get is that when I do a trace it shows my INSERT code
in the Begin PostBack which looks like I would have access to the
variable.
I'm sorry to keep responding to myself, but it looks like the lifecycle
is as follows:

Page_Load
Button_click

So,

Page_Load fails to show a Session Variable or any other because it has
not been initialized yet.
Button_click is where the row is inserted and the last ID is given.

But because the Button_click has fired after the Page_load the
page_load never sees the value.

So I must find a way to get the last row id..oh wait..I populate the
controls after the insert in that click event instead of the Page_Load
event.

Thanks!
Umm, glad to be of assistance? :)

Mythran
needin4mation@.gmail.com wrote:

> I'm sorry to keep responding to myself, but it looks like the
> lifecycle is as follows:
> Page_Load
> Button_click

RTM...

http://msdn.microsoft.com/library/d...y/en-us/cpguide
/html/cpconControlExecutionLifecycle.asp

;-)

--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Please Help me understand..

I want to create a page that pulls a specific record from a database based on the value passed from a Request.QueryString. If the value is not in the string then it uses a default value of 1(one). Here is what I have so far:

' Determine if a Content ID has been passed in the query string
' If so use it as a variable in our SQL string to grab content for the page
' Httpcontext.Request.Querystring("Content_id")

Sub BindHomeBodyData() ' GRAB CONTENT *************************

Const strSQL as String = "SELECT * FROM Content WHERE Content_ID = " & Httpcontext.Request.Querystring("Content_id")
Dim myCommand as New SqlCommand(strSQL, myConnection)
Dim myDA as New SqlDataAdapter()
myDA.SelectCommand = myCommand
Dim myDS as New DataSet()
myDA.Fill(myDS)
dlHomeBodyData.DataSource = myDS
dlHomeBodyData.DataBind()

End SubNot tested:

Dim Content_ID As Integer = 1

If Not IsNull(Request.QueryString("Content_id")) Then
Dim myRegEx As New RegEx("[^0-9]"), sContent As String = myRegEx.Replace(Request.QueryString("Content_id"), "")

If sContent <> "" Then
Content_ID = CInt(sContent)
End If
End If


to take what you have given me and place it into what I have. Sorry I am an extreme newbie. Here is what I have is there any way you could educate me here and show me how to write this out according to my example. Thanks a lot I appreciate it.

Sub BindHomeBodyData() ' GRAB CONTENT *************************

Const strSQL as String = "SELECT * FROM Content WHERE Content_ID = " & Httpcontext.Request.Querystring("Content_id")
Dim myCommand as New SqlCommand(strSQL, myConnection)
Dim myDA as New SqlDataAdapter()
myDA.SelectCommand = myCommand
Dim myDS as New DataSet()
myDA.Fill(myDS)
dlHomeBodyData.DataSource = myDS
dlHomeBodyData.DataBind()

End Sub

Please help me with this connection to the database problem!

hello everyone!
I am very new to the ASP.NET, lately I have been practicing about accessing data through Access 2002 file with ASP.NET. At the beginning, it really gave me a headache. here is my problem:
My goal is going to store User's Username, password and repassword into a db file called userDB.mdb
the project has two .aspx files as WebForm1 and 2
--------------------------------
//here is the code for the WebForm1:
(i will only provide those code-behind code, just make the message clear, if anyone needs the html code, please let me know)
--------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

namespace uncos
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label t_Username;
protected System.Web.UI.WebControls.Label t_Password;
protected System.Web.UI.WebControls.Label t_Repassword;
protected System.Web.UI.WebControls.TextBox tb_Username;
protected System.Web.UI.WebControls.TextBox tb_Password;
protected System.Web.UI.WebControls.TextBox tb_Repassword;
protected System.Web.UI.WebControls.RequiredFieldValidator val_Username;
protected System.Web.UI.WebControls.RequiredFieldValidator val_Password;
protected System.Web.UI.WebControls.CompareValidator val_Repassword;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
if (tb_Password.Text == tb_Repassword.Text)
{
Response.Redirect(@dotnet.itags.org."WebForm2.aspx");
}
}
}
}

============================================================
//here is the code for the WebForm2:
============================================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Data.OleDb;
using System.Collections.Specialized;

namespace uncos
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
NameValueCollection dataColl;
dataColl = Request.Form;
string tbUsername = dataColl["tb_UserName"];
string tbPassword = dataColl["tb_Password"];
string tbRepassword = dataColl["tb_Repassword"];

OleDbConnection cnn = new OleDbConnection(@dotnet.itags.org."Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\userDB.mdb");
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "INSERT INTO User_Table(User_ID,Password,Repassword) VALUES('"+tbUsername+"','"+tbPassword+"','"+tbRepassword+"')";
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;

try
{
cnn.Open();
cmd.ExecuteNonQuery();

}
catch (Exception ex)
{
Label1.Text=ex.ToString();
}
finally
{
if(cnn.State == ConnectionState.Open)
{
cnn.Close();
}
}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

============================================================
//It has runtime error.

//the error message is:
============================================================
System.Data.OleDb.OleDbException: The Microsoft Jet database engine cannot open the file 'c:\userDB.mdb'. It is already opened exclusively by another user, or you need permission to view its data. at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbConnection.InitializeProvider() at System.Data.OleDb.OleDbConnection.Open() at uncos.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\uncos\webform2.aspx.cs:line 40

============================================================
I have been doing lots of reserch to solve this problem, but none of them work.
I don't have the problems of file or folder sharing, all the accounts on my PC has the full control to that .mdb file.

.mdb file is not in the Inetpub folder as well, I put it under C:\, just in case the security permission problem occurs.

All the programs who can access that .mdb file are closed before I test the page.

I can't find anything else could cause the problem.

Please help me!!! Cheers!!!!

LeeMake sure that your account that runs ASP.NET applications has sufficient security privledges to the directory that the Access database is in.
Thanks for your advise, I am using the Administrater Account on my PC (it's XP), I have give this account full control of the C driver. But nothing changes.

Lee
No, the asp.net worker process uses an account (probably a user named ASP.NET on XP).. give this user permission to the directory, not the user you are logged in with.
Thanks again!!!

I have got four accounts on my PC.

they are :

MyName(Computer Adminstrater)

SQLDebugger(Limited Account; Password protected)

aspnet_wp account(Limited Account; Password protected)

Guest Account ( Guest Account is off)

at the moment I am in (MyName) account. did you mean that i need to login (aspnet_wp) account and give the permission to the folder and file? or other accounts maybe

cheers!!

Lee
I have reinstalled SDK1.1, it was 1.0. now that permission problem has solved:)

but i have got another problem, this time when i run the application, the errors like:
========================================================
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at uncos.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\uncos\webform2.aspx.cs:line 41
=========================================================
the "Insert Into" is in the WebForm2.aspx

thanks for your guys have been help me!! Cheers

Lee
Please do a research on "Sql Injection Attack". Your code is wide open to this type of attacks.
thanks bleroy, i think i really learned a lot here.

this project won't upload to any server, it is just a practice made by myself. my goal is just insert data into database file from user's input. i didn't really put very much consideration on the security issues. but your advise is valuable for me, thank you very much! Cheers!

i have changed the syntax a little bit, but the problem is still the same.

there is one thing i don't understand, if it is a syntax error, why when i compile it , it didn't give the error warning?

Cheers!

Lee
Thanks for your guys. I had solved my problems. :) I changed the code quite a lot. and it's simplier. it works now,

Cheers!

PLEASE HELP ME! Access to SQL-Server!?!

Hi to all!

I am new to asp and databases...I got a program, that uses an access database...now I want the program to write the information into a SQL-database...what must I do?

Or what is important to change on the code?

thx

juviFirst migrate the data from access to SQL Server using the tools provided by SQL. Second, you will need to change your connection string to use the SQL data provider (www.connectionstrings.com). Lastly, you will probably need to change some of your queries b/c access queries are slightly different from T-SQL queries.

please help me..... sms service

Hi evrybody, I am developing a website using asp.net with VB.net and access database.. the website is almost completed...but i have to finish one more small part. the website administrator should be able to send sms to the mobile number exist in the DB. i know that we should register to some sms provider which will supplement us with a user name and password.. I dont know how to implement it yet... and i have no clue about doing that.. I dont want to register to the sms provider yet since i am still working in the demo and i did not sell the website yet.. but i have this idea.. i hope if it will work. i have a DSL account in saudi.net (my.saudi.net.sa) company that provide me with username, pass, and numbers of free sms message and i am thinking to use them instead of creating an account in some provider. i hope if you help me in coding that to send sms message through my website using my account in saudinet. if my idea does not work, then please advice me for a provider and the code to send it if possible.. all what i can add here is that my work is stopped because of that and i will really appreciate any help here.. and please i am in hurry :)

Do you have console access to your site? If so create a queue table within your database as that your web application writes to this table. Then write a windows service to read this queue and call the SMS provider. Thus you can easily change the SMS provider.

Consuming such a web service is relatively easy, just import the wsdl to create a web reference and explore the resulting methods. It does help if the SMS provider gives you some sample code for their service. Code for other SMS providers will probably have a different interface and thus unlikely to be of help.


Hello,

This may be helpful to you,

http://www.codeproject.com/aspnet/SendingSMS.asphttp://www.zopensource.com/http://www.c4sms.com/codeExamples.asp?linkhref=dotnet