Showing posts with label drop. Show all posts
Showing posts with label drop. Show all posts

Wednesday, March 21, 2012

Post to a DB

Alright so here is what I am trying to do.

I have a form that someone fills out it has a text box as title, and a drop down box that is a category, and then a text area that is for their explanation.

On the back end I am using a stored procedure called sp_store_bkm. When I execute this it works just fine and puts the data that I put in it into the to table below is the Stored procedure code:

ALTER PROCEDURE sp_store_bkm
@.oID nvarchar OUTPUT,
@.oTitle nvarchar(50),
@.oCategory nvarchar(50),
@.obkmtext nvarchar(MAX)

AS BEGIN

INSERT INTO tbl_bkms(Title, Category, bkmtext)
VALUES(@.oTitle, @.oCategory, @.obkmtext)
Set @.oID= SCOPE_IDENTITY()
END

Now on my front end it comes up with an error in the lower left (erros on page). When I click on the error for details it seems like it is coming fromt he connection string. I cant find anything wrong with the connection string. Below is my code for the aspx page.

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


<script>

function Submit2_onclick() {

Dim Connection As SqlConnection = "server=localhost;Database=BKM.mdf;integrated security=SSPI;"
connection.Open()
Try
Dim command As SqlCommand = New SqlCommand("sp_store_bkm", connection)

command.CommandType = CommandType.StoredProcedure
Dim oID As New SqlParameter("@.oID", SqlDbType.Int)
oID.Direction = ParameterDirection.Output

command.Parameters.Add(oID)
command.Parameters.Add("@.oTitle", title.text)
command.Parameters.Add("@.oCategory", category.text)
command.Parameters.Add("@.obkmtext", bkmtext.text)
command.ExecuteNonQuery()

Dim sOrderID As String = oID.Value }
</script>

<form method="post">
<table cellpadding="10" style="width: 100%">
<tr>
<td style="width: 100px">
<span style="font-size: 10pt; font-family: Verdana">
Login ID:
<br />
</span>
<asp:LoginName ID="LoginName1" runat="server" Font-Names="Verdana" Font-Size="10pt" ForeColor="Red" />
<span style="font-size: 10pt; font-family: Verdana">
<br />
<br />
Title:<br />
</span>
<input id="title" style="width: 374px" type="text" /><br />
<br />
<span style="font-size: 10pt; font-family: Verdana">
Category:<br />
</span>
<select id="Category" name="D1" size="1" language="javascript" onclick="return Select1_onclick()">
<option selected="selected">Office Applications</option>
<option>VPN</option>
<option>WLAN</option>
</select>

<br />
<span style="font-size: 10pt; font-family: Verdana">
<br />
Your BKM<br />
</span>
<textarea id="bkmtext" style="width: 378px; height: 196px"></textarea><br />
<br />
<input id="Reset1" type="reset" value="reset" />
<input id="Submit2" type="submit" value="submit" language="javascript" onclick="return Submit2_onclick()" /></td>
</tr>
</table>
</form>
</asp:Content>

Please help.

What,exactly is the error message?|||

Well I am closer now. I dont get errors on the page, but nothing gets posted into the DB. If there is an easier way to do this let me know. This is the way I was told to do it.

below is the aspx page, the stored procedure is still the same.

<%@. Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


<script language=vbscript type="text/vb">

function Submit2_onclick()

Dim Connection;As SqlConnection = 'Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\BKM.mdf;Integrated Security=True;User Instance=True'
connection.Open()
Try
Dim command As SqlCommand = New SqlCommand("sp_store_bkm", connection)

command.CommandType = CommandType.StoredProcedure
Dim oID As New SqlParameter("@.oID", SqlDbType.Int)
oID.Direction = ParameterDirection.Output

command.Parameters.Add(oID)
command.Parameters.Add("@.oTitle", title.text)
command.Parameters.Add("@.oCategory", category.text)
command.Parameters.Add("@.obkmtext", bkmtext.text)
command.ExecuteNonQuery()

Dim sOrderID As String = oID.Value
End function
</script>

<form method="post">
<table cellpadding="10" style="width: 100%">
<tr>
<td style="width: 100px">
<span style="font-size: 10pt; font-family: Verdana">
Login ID:
<br />
</span>
<asp:LoginName ID="LoginName1" runat="server" Font-Names="Verdana" Font-Size="10pt" ForeColor="Red" />
<span style="font-size: 10pt; font-family: Verdana">
<br />
<br />
Title:<br />
</span>
<input id="title" type="text" /><br />
<br />
<span style="font-size: 10pt; font-family: Verdana">
Category:<br />
</span> <select id="category">

<option selected="selected"></option>
<option>VPN</option>
</select>

<br />
<span style="font-size: 10pt; font-family: Verdana">
<br />
Your BKM<br />
</span>
<textarea id="bkmtext" style="width: 589px; height: 179px"></textarea><br />
<input id="Reset1" type="reset" value="reset" />
<input id="Submit2" type="submit" value="submit BKM" language=vbscript /></td>
</tr>
</table>
</form>
</asp:Content>

|||

now I get the error when I click submit that says

line 265
char: 1
Error: Type mismatch: 'Submit2_onclick'
Code: 0
URL: http://localhost:1755/rvosd_website/bkm/default.aspx

Friday, March 9, 2012

Possible to drop IDENTITY from a column?

I have several tables with the IDENTITY attribute (my problem now!) and I
need to remove the IDENTITY attribute from some of those tables/columns. Is
there a sane way of doing it? If so, could you share it with me?
Thanks!
MichaelUnfortumately not.
"Snake" <Snake@.discussions.microsoft.com> wrote in message
news:46DDBEBD-8F2D-41D9-922B-59FF098E88A2@.microsoft.com...
>I have several tables with the IDENTITY attribute (my problem now!) and I
> need to remove the IDENTITY attribute from some of those tables/columns.
> Is
> there a sane way of doing it? If so, could you share it with me?
> Thanks!
> Michael|||Not easy. You could create a new column, populate it with the old data from
the IDENTITY column then change any referencing indexes, constraints, etc
and drop the old column.
Alternatively, if you remove the IDENTITY property using Enterprise
Manager's table designer it will drop and re-create the table for you. Not
something you want to do while the system is in use though.
David Portas
SQL Server MVP
--|||Really not easy, Itzik wrote an article about that, where you can find the
information from behind the scenes:
http://www.windowsitpro.com/Article...22080.html?Ad=1
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Snake" <Snake@.discussions.microsoft.com> schrieb im Newsbeitrag
news:46DDBEBD-8F2D-41D9-922B-59FF098E88A2@.microsoft.com...
>I have several tables with the IDENTITY attribute (my problem now!) and I
> need to remove the IDENTITY attribute from some of those tables/columns.
> Is
> there a sane way of doing it? If so, could you share it with me?
> Thanks!
> Michael