|
Glad you liked it. Without it I don't think I would have gotten into javascript. Too much like the old Cobol programming I used to have to do with the "I am here" to debug.
Ben
|
|
|
|
|
Hi
I have built a simple page which will should send a persons firstname and lastname to mysql database, i am not sure how to code the submit button as i obviously need it to call my method for sending data to the server based on the input in my text boxes.
Any suggestions, i recognise is probably fundamental but am newbie to asp and not got much web development background
This is what I have
<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="VB" runat="server">
Sub page_load()
End Sub
''' <summary>
''' Page_load
''' Recognised by ASP and must be provided on loading of page.
'''
''' Creates connection to database, passes stored procedure into test database
''' and fills a table, which is showing in web browser
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Sub sendData(ByVal sender As Object, ByVal e As EventArgs)
'Create connection string to pass database, string holds login information to mySQL,
Dim connectionString As String
connectionString = "Server=; uid=; pwd=;database=;"
'Builds .net mysql connection and passes connection string into method
Dim connection As New MySqlConnection(connectionString)
'Open connection to DB
connection.Open()
'Create mySql command string for passing query or SPROC(Stored Procedure)
Dim cmdString As New MySqlCommand
'Set Command to equal mySql connection,t so can pass SQL query
cmdString.Connection = connection
'Set command string to equal SPROC
cmdString.CommandText = "insertmessage"
'ONLY PLACE THIS IF SPROC, sets the command to a SPROC
cmdString.CommandType = CommandType.StoredProcedure
Dim param As New MySqlParameter
param = cmdString.Parameters.Add("param1", SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Input
param.Value = txtFirstName.Text
param = cmdString.Parameters.Add("param2", SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Input
param.Value = txtLastName.Text
cmdString.ExecuteNonQuery()
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="vbscript" type="text/vbscript">
</script>
</head>
<body>
<form id="form1" runat="server">
ENTER FIRSTNAME<asp:TextBox runat="server" ID="txtFirstName">
</asp:TextBox><br /><br />
ENTER LAST NAME
<asp:TextBox runat="server" ID="txtLastName"></asp:TextBox>
<asp:Button runat="server" ID="submit" Text="Submit" />
</form>
</body>
</html>
|
|
|
|
|
Other than hard coding your connection string, rather than placing it in the web.config file, I think you've got the right idea.
only two letters away from being an asset
|
|
|
|
|
Two things:
1) It looks as though you are not using Visual Studio, but have your server code inline - ie in the same file - as you have pasted it here. In this case you need to let the page know which procedure is to be associated with the button click event. Like this:
<asp:Button runat="server" ID="submit" Text="Submit" onclick="sendData" />
2) Within your sendData procedure, you must remember to close the database connection after use. Really, you ought to wrap the code in a try...catch...end try block - something like:
try
connection.Open()
' do your db stuff...
connection.CLose()
catch
If connection.State = ConnectionState.Open Then connection.Close()
end try
cheers
Fred
|
|
|
|
|
I have made the necessary changes as you have said above, it jus keeps falling through to the catch statement tho
any more suggestions?
I have debugged and it seems to go thru as expeced also
<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="VB" runat="server">
Sub page_load()
End Sub
''' <summary>
''' Page_load
''' Recognised by ASP and must be provided on loading of page.
'''
''' Creates connection to database, passes stored procedure into test database
''' and fills a table, which is showing in web browser
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Sub sendData(ByVal sender As Object, ByVal e As EventArgs)
Try
'Create connection string to pass database, string holds login information to mySQL,
Dim connectionString As String
connectionString = "Server=localhost; uid=jshort; pwd=oasisarab;database=test;"
'Builds .net mysql connection and passes connection string into method
Dim connection As New MySqlConnection(connectionString)
'Open connection to DB
connection.Open()
'Create mySql command string for passing query or SPROC(Stored Procedure)
Dim cmdString As New MySqlCommand
'Set Command to equal mySql connection,t so can pass SQL query
cmdString.Connection = connection
'Set command string to equal SPROC
cmdString.CommandText = "insertmessage"
'ONLY PLACE THIS IF SPROC, sets the command to a SPROC
cmdString.CommandType = CommandType.StoredProcedure
Dim param As New MySqlParameter
param = cmdString.Parameters.Add("param1", SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Input
param.Value = txtFirstName.Text
param = cmdString.Parameters.Add("param2", SqlDbType.VarChar, 50)
param.Direction = ParameterDirection.Input
param.Value = txtLastName.Text
cmdString.ExecuteNonQuery()
connection.Close()
Catch
MsgBox("Broken")
End Try
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script language="vbscript" type="text/vbscript">
</script>
</head>
<body>
<form id="form1" runat="server">
ENTER FIRSTNAME<asp:TextBox runat="server" ID="txtFirstName">
</asp:TextBox><br /><br />
ENTER LAST NAME
<asp:TextBox runat="server" ID="txtLastName"></asp:TextBox>
<asp:Button runat="server" ID="submit" Text="Submit" onclick="sendData" />
</form>
</body>
</html>
|
|
|
|
|
Add a literal control to the page (anywhere)
<asp:Literal runat="server" id="litErr" />
Then replace the catch bit with
catch ex as exception
litErr.Text = ex.Message
That should give you a better idea of where the error is...
cheers
Fred
|
|
|
|
|
on debugging it says that my parameter thats being passed to the stored procedure isn't defined, which i don't understand as i have it defined within the procedure.
This is the code from my procedure
CREATE DEFINER=`myusername`@`localhost` PROCEDURE `InsertMessage`(IN param1 VARCHAR(50), IN param2
VARCHAR(50))
BEGIN
INSERT INTO names(firstName, lastname)
VALUES(param1,param2);
END
|
|
|
|
|
Don't paramater names in SP's have to start with an @ sign? I think so...
Add these to your SP and don't forget to amend your vb code accordingly...
Fred
|
|
|
|
|
Hi All,
Please help me...
I want Import and Export data from excel or access to Sql Server from software
Language: asp.net using Vb
version:.Net 2005
Thank you..
|
|
|
|
|
Are you asking for help in doing this or posting a job requirement?
If the former, what have you done so far? If the latter, wrong forum.
only two letters away from being an asset
|
|
|
|
|
Hi,
i am building a application in which user register with our website.
As soon as he register an entry of his email address is made in database table.
Now I have to send him a mail as soon as he register .
i have build a console program to send him mail by picking emailaddress from DB table.
But I want to make my email program autoresponding means as soon as any user sign up an email is sent to him..
How can I do that..Plz provide me answer it is very crucial..
hiiiiii
|
|
|
|
|
hkchauhan wrote: have build a console program to send him mail by picking emailaddress from DB table
So you have the code to extract and send the email. What part are you missing?
only two letters away from being an asset
|
|
|
|
|
hkchauhan wrote: i have build a console program to send him mail by picking emailaddress from DB table.
You don't need this application. You can send mail from the Register page itself. You have to send the mail after the data is stored in to the Database.
|
|
|
|
|
Hi,
I have to upload a file, and I saw hat you must specify the form attributes like:
<form Method="Post" EncType="Multipart/Form-Data" RunAt="Server">
But I have a little problem. I am using master pages, and I have my <form></form> specified in the master page.
What do I do now?
ma se
|
|
|
|
|
Hi ma se,
I want to tell you that you dont need to include EncType in your code for uploading file.
You can use fileuplaod control for uploading any file..
I may be wrong but i never use EncType for uploading file.
Also you can use fileupload control in master page too.
|
|
|
|
|
Hi,
In a web form, user enters the SQL query in a Multi-line asp TextBox. But the the formatting is such a way that sometimes the Column names gets broken or wrapped.
So while executing, I get error from our data layer. Is there a way to avoid this?
Regards,
Blumen
|
|
|
|
|
I think it is a problem of "" in your string.
But can not say properly.
You should give some more detail
|
|
|
|
|
Viral Upadhyay wrote: You should give some more detail
Example Query:
Select Column_Name1,Column_Name2,Column_Name3 from Table1
The above query (assume its very long) would look something like this in a multi-line asp textbox:
Select Column_Name1,Column
_Name2,Column_Name3 from Table1
So here the columnname 2 is broken, and it causes error in DB.
Blumen
|
|
|
|
|
See it may be because some ecape charactor inserted there so try to remove that charactor may be it works
|
|
|
|
|
pls give me regular expression so that the starting and ending of the string does not have special character and no two consecutive characters be special characters.
thanks in advance.
|
|
|
|
|
Hi,
People don't normally give out answers if they see you haven't tried.
Regular expressions are difficult for me, I normally go to the following website if I need help:
http://regexlib.com/[^]
Regards
ma se
|
|
|
|
|
Good site tip - thanks
|
|
|
|
|
Hi all.
How can we make our web site's contents center aligned on every page like most web sites have their contents in center and keep left and right sapces for nevigations and advertisments.
As I tried it using master pages and css but it is not working.
Is there any simple solutions to do it ot any sample code for this.
Thanks in advance.
Bye
Bajrang Singh
Using .net 2.0 (VS2005)
|
|
|
|
|
Create a container table or div and make it center aligned
|
|
|
|
|
Hi guys,
i have an doubt in Asp.net webservice. I have 2 different web services and inserting the data in 2 different databases.
Web services calling from "Button_click" event in the web page. Once clicked means, the first web service is called and inserting the data to DB. If success,then call 2nd Web service WebMethod.The 2nd Web service web method fails means ,then i want to roll back the first web service transactions.
How to achieve this? how to maintain the transactions across the web service.
Thanks & Regards
d.sengottuvelu
|
|
|
|