|
I am inserting a new row in a database table (MSSQL).
I want to retrieve the value of Identity column associated with 'this' new row.
My stored procedure is as follows :
ALTER PROCEDURE dbo.Insert
(
@SubCategoryId tinyint,
@text nvarchar(MAX),
@Url nvarchar(2000)
)
AS
SET NOCOUNT ON;
INSERT INTO Table1
(SubCategoryId, text, Url)
VALUES (@SubCategoryId,@text,@Url)
SELECT NEWID = SCOPE_IDENTITY()
Now, I have a table-adapter in which i have any Insert function which uses the above stored procedure.
From the code-behind, i am inserting the data.
DataSetTableAdapters.Table1TableAdapter t1 = new DataSetTableAdapters.Table1TableAdapter();
int result = t1.Insert((byte)int.Parse(ddlSubCategory.SelectedValue), txtText.Text, txtUrl.Text);
The row is inserted in the database, but the returned value is not the Identity column ...
Is the stored procedure incorrect ?
I posted this in ASP.NET forum, because i want to do this in ASP.NET, i found the stored procedure on a database related site, still the stored-procedure is not working ...
Apurv
“Never trust a computer you can’t throw out a window.”
(Steve Wozniak)
“There are only two industries that refer to their customers as ‘users’.”
(Edward Tufte)
|
|
|
|
|
It's still a SQL question.
Does 'I found the stored proc' mean you don't really understand what it does ? I suspect your core issue is probably that the table adapter 's insert method probably doesn't return the result of the proc, but a value such as the number of rows changed. Hard to say, you don't say what value you're getting back, but SCOPE_IDENTITY() will return that new id, so I don't see what the issue could be. The reason to use this is, it will return the id that your proc created, if you added SQL to find the highest id, and it was called by two users at once, you'd have a race condition.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Does 'I found the stored proc' mean you don't really understand what it does ?
not 100% true.
Actually I am not good at writing the stored procedures.
Christian Graus wrote: the table adapter 's insert method probably doesn't return the result of the proc
this could be the issue ...
But my task is straight forward, I have to first Insert a row in one table, then using the value of the Identity column of the created row, some rows are to have inserted into other table where, the primary-key in this table is Foreign key in the other table.
What should be the approach to this problem ?
Apurv
“Never trust a computer you can’t throw out a window.”
(Steve Wozniak)
“There are only two industries that refer to their customers as ‘users’.”
(Edward Tufte)
|
|
|
|
|
how to call function in class page to default.asp x
|
|
|
|
|
Umm, MethodName(//PossibleParameters)
I would highly suggest getting a book on ASP.NET, C#/VB.NET if you don't know how to even call a method.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
This guy is either a troll, or an absolute moron. I'd recommend ignoring his posts.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
OK, at this point I am certain that this is some sort of joke. Your questiosn get stupider and stupider, it's obvious that you can't be serious. The joke isn't funny, please stop it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi all,
First of all i wud like to express my heartiest gratitude to the expertsof codeproject who have been helping me time to time so that i dont remain stuck with a particular problem.
My Prob:
I was using VS2005 for building my application but suddenly due to some unavoidable circumstances we are forced to migrate to VS2003.But I am not too well-versed with VS2003 andm finding it a bit difficult to convert my app into VS2003.
One such problem is that I was using string.contains in VS2005 but now I see that it doesnt exist in VS2003.So I wud like to know is there a way to implement the same feature in VS2003??plz help me out!!!!
|
|
|
|
|
First of all, this has nothing to do with visual studio. VS is just an editor. Documentation[^] for string.Contains says it is supported only on .NET framework 3.0 or later. In .NET 1.1, you have to use String.IndexOf[^] method to see whether a character exist or not.
|
|
|
|
|
I have a table in a database with certain fields which the user fills up through a form.At a later point,if the user wishes to see this form,I need to auto-fill those fields.The auto-fill works except for the DropDownList control.It always sets its field to the first item in the datalist.I tried 'DropDownList2.Items.FindByText(string).selected="True"' but it shows an error. I need the dropdownlist to show the text that was previously selected by the user and also giving the user an option to change his previous selection.
How do i do this?
|
|
|
|
|
DropDownList.Items.IndexOf(DropDownList.Items.FindByValue("InsertValueToFind"))
That is one of the ways I do it.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
|
Do you set the value of the DropDownList, or just the text?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Try the FindByText one.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
HI. got a project where you have a file menu, and you open a text file, then save the text file. and a exit menu item. now, if i click the open file menu item, it displays two text boxes, where you enter a name and phone number. but for some stupid reason, if i click the save menu item, i get a message saying the file needs to be open, and does not save the file? so what am i doing wrong and how to fix this? any help would be gretefully aprreciated. will post the code below. cheers Marvin.
'Program: Ch11 Open and Write File
'Programmer: Marvin Hunkin
'Date:Saturday March 7 2009
'Description: Allow the user to enter names and phone numbers and
' save them in a file.
Imports System.IO
Public Class frmCh11OpenAndWriteFile
' Declare module-level variable.
Dim PhoneStreamWriter As StreamWriter
Private Sub menSaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menSaveToolStripMenuItem.Click
' Save the record to the file.
If PhoneStreamWriter IsNot Nothing Then ' Is the file open?
With Me
PhoneStreamWriter.WriteLine(.tbNameTextBox.Text)
PhoneStreamWriter.WriteLine(.tbPhoneTextBox.Text)
With .tbNameTextBox
.Clear()
.Focus()
End With
With .tbPhoneTextBox
End With
End With
Else ' File is not open
MessageBox.Show("You must open the file before you can save a record", _
"File Not Open", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub menOpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menOpenToolStripMenuItem.Click
' Open the file.
Dim dlgResponseDialogResult As DialogResult
' Is the file already open?
If PhoneStreamWriter IsNot Nothing Then
PhoneStreamWriter.Close()
End If
' Begin in the project folder.
dlgOpenFileDialog.InitialDirectory = "C:\" ' Display the File Open dialog box.
' Make sure that the user didn’t click the Cancel button.
If dlgResponseDialogResult <> DialogResult.Cancel Then
' Open the output file.
End If
End Sub
Private Sub menExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menExitToolStripMenuItem.Click
' Close the file and the form.
If PhoneStreamWriter IsNot Nothing Then ' Is the file open?
PhoneStreamWriter.Close()
End If
Me.Close()
End Sub
End Class
|
|
|
|
|
In your code, when you want to open the file, you need something like this:
dim filePath as String = "" 'fully qualified path to the file
dim sw as New StreamWriter(filePath)
'write what you want to the file
sw.Close()
Try that, and if you still have problems post back, but I suggest you wrap your code snippets with the <pre></pre> tags.
|
|
|
|
|
Does it not feel strange to have posted a VB.NET question in an ASP.NET forum?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
hI. SORRY ABOUT THAT. FORGOT I WAS IN THE ASP FORUM. SHOULD HAVE GONE TO THE VB FORUM. SORRY ABOUT THAT. HAD A SNEIOR MEOMENT AND FORGOT WAS IN THE WRONG FORUM. SO PLEASE FROGIVE ME FOR THAT MISTAKE. WAS TIRED AND FORGOT I HAD POSTED IN THE WRONG AREA. SO WILL NOT DO THAT AGAIN. CHEERS mARVIN.
|
|
|
|
|
Hi. welltried your suggestion, but think i got my self a bit confused and a bit muddled. so will paste the error below. got an exception error for line 96. can any one help. will paste the error as a graphic below and the code. so help me to get this working. what should i take out and keep in the code? cheers Marvin.
sender As Object, ByVal e As System.EventArgs) Han
'Program: Ch11 Open and Write File
'Programmer: Marvin Hunkin
'Date:Saturday March 7 2009
'Description: Allow the user to enter names and phone numbers and
' save them in a file.
Imports System.IO
Public Class frmCh11OpenAndWriteFile
' Declare module-level variable.
Dim PhoneStreamWriter As StreamWriter
Private Sub menSaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menSaveToolStripMenuItem.Click
' Save the record to the file.
If PhoneStreamWriter IsNot Nothing Then ' Is the file open?
With Me
PhoneStreamWriter.WriteLine(.tbNameTextBox.Text)
PhoneStreamWriter.WriteLine(.tbPhoneTextBox.Text)
With .tbNameTextBox
.Clear()
.Focus()
End With
With .tbPhoneTextBox
.clear()
.focus()
End With
.tbPhoneTextBox.clear()
End With
Else ' File is not open
MessageBox.Show("You must open the file before you can save a record", _
"File Not Open", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub menOpenToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menOpenToolStripMenuItem.Click
' Open the file.
dim strFilePath as String = "c:\Test.txt"
Dim dlgResponseDialogResult As DialogResult
' Is the file already open?
If PhoneStreamWriter IsNot Nothing Then
PhoneStreamWriter.Close()
End If
' Begin in the project folder.
dlgOpenFileDialog.InitialDirectory = "C:\" ' Display the File Open dialog box.
' Make sure that the user didn’t click the Cancel button.
If dlgResponseDialogResult <> DialogResult.Cancel Then
' Open the output file.
PhoneStreamWriter.WriteLine(tbNameTextBox.Text)
PhoneStreamWriter.WriteLine(tbPhoneTextBox.Text)
End If
End Sub
Private Sub menExitToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles menExitToolStripMenuItem.Click
' Close the file and the form.
If PhoneStreamWriter IsNot Nothing Then ' Is the file open?
PhoneStreamWriter.Close()
End If
Me.Close()
End Sub
End Class
|
|
|
|
|
Aspx page return the following error
(Valid values are between 1 and 9666, inclusive.Parameter name: year )
when I am trying to Add calander from the tool box.
I am using the following culure in page tage:
UICulture="ar-sa" Culture="ar-SA"
I tried to use the following code in the load page:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ar-SA");
System.Threading.Thread.CurrentThread.CurrentUICulture = ci; System.Threading.Thread.CurrentThread.CurrentCulture = ci;
but the same error returned
I adjust the Calander setting from control Panel to Higri calander and then
to grogrian calander but also the same error returne.
thanks in Advance
Mohammed Ibrahim
|
|
|
|
|
You shouldn't have this problem. Hijri year values are 600 years less than Gregorian.
Can you capture what value is going in? My guess is that nothing or null is being input and its getting casted into a 0 which would break the rule. You should set the default to DateTime.Now.Year.
If that's not the case, post back, but include the value being input and the snippet where its being handled.
|
|
|
|
|
|
I am not Passing any date what I am doing is
adding Clander control from the tool box
then writing the following lines in page load event:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ar-SA");
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentCulture = ci;
System.Threading.Thread.CurrentThread.CurrentUICulture = ci;
then I am getting the following error:
Server Error in '/COEIA' Application.
--------------------------------------------------------------------------------
Valid values are between 1 and 9666, inclusive.
Parameter name: year
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Valid values are between 1 and 9666, inclusive.
Parameter name: year
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentOutOfRangeException: Valid values are between 1 and 9666, inclusive.
Parameter name: year]
System.Globalization.HijriCalendar.CheckYearRange(Int32 year, Int32 era) +2315381
System.Globalization.HijriCalendar.GetDaysInYear(Int32 year, Int32 era) +20
System.Globalization.HijriCalendar.GetDatePart(Int64 ticks, Int32 part) +234
System.Globalization.HijriCalendar.GetYear(DateTime time) +26
System.Web.UI.WebControls.Calendar.IsTheSameYearMonth(DateTime date1, DateTime date2) +73
System.Web.UI.WebControls.Calendar.EffectiveVisibleDate() +163
System.Web.UI.WebControls.Calendar.Render(HtmlTextWriter writer) +89
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +163
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +51
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
Mohammed Ibrahim
|
|
|
|
|
Hi. got a project where you enter details for an order, name, address, city, state, zip code, description, quantity, weight and price, then you click the add this button, which adds individual items to an order. then it calculates individual items. then you click the up date summary button, and then calculate all items for the entire order. then it displays the dollar amount, sales tax, if shipped to a california address, and is 8% of the total price, shows the shipping charge for a given weight. and then the total amount. the problem, is not showing the correct dollar amount, sales tax, if i put in the state which is:
CA, not showing the correct amount. what am i doing wrong? can any one help me to get this working? any suggestions, code samples, code snippets would be fine. cheers Marvin.
'Program: VBMail
'Programmer: Marvin Hunkin
'Date: Tuesday Febuary 24 2009
'Description: Keep track of mail orders
Partial Class VBMail
Inherits System.Web.UI.Page
'Declare Constants
Const Handling As Decimal = 0.25
'Declare Module Level Variables
Dim intTotalWeightShipped As Integer = 0
Dim decTotalPriceCharged As Decimal = 0.0
Protected Sub btnAddThisButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddThisButton.Click
'Declare Variables
Dim intItemQuantity As Integer = 0
Dim intItemWeight As Integer = 0
Dim intTotalOrderWeight As Integer = 0
Dim decItemPrice As Decimal = 0.0
Dim decTotalOrderPrice As Decimal = 0.0
Dim decShippingCharge As Decimal = 0.0
Dim decHandling As Decimal = 0.0
Dim decTax As Decimal = 0.0
Dim decTotalAmount As Decimal = 0.0
'Convert Variables
intItemQuantity = integer.parse(tbQuantityTextbox.Text)
intItemWeight = integer.Parse(tbWeightTextBox.Text)
decItemPrice = decimal.parse(tbPriceTextBox.Text)
'Calculate Items
decTotalOrderPrice = intItemQuantity * decItemPrice
intTotalOrderWeight = intItemQuantity * intItemWeight
decTotalPriceCharged = decTotalPriceCharged + decTotalOrderPrice
intTotalWeightShipped = intTotalWeightShipped + intTotalOrderWeight
tbPriceTextBox.Text = decItemPrice.ToString("C")
tbNameTextBox.Focus()
End Sub
Protected Sub btnClearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClearButton.Click
'Clear Text Boxes
tbNameTextBox.Text = ""
tbAddressTextBox.Text = ""
tbCityTextBox.Text = ""
tbStateTextBox.Text = ""
tbZipCodeTextBox.Text = ""
tbDescriptionTextBox.Text = ""
tbQuantityTextBox.Text = ""
tbWeightTextBox.Text = ""
tbPriceTextBox.Text = ""
tbDollarAmountTextBox.Text = ""
tbSalesTaxTextBox.Text = ""
tbShippingChargeTextBox.Text = ""
tbTotalAmountTextBox.Text = ""
decTotalPriceCharged =0.0
intTotalWeightShipped = 0
tbNameTextBox.Focus()
End Sub
Protected Sub btnSummaryButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSummaryButton.Click
Dim strState As String = "CA"
Dim intItemWeight As Integer = 0
Dim intTotalOrderWeight As Integer = 0
Dim decTotalOrderPrice As Decimal = 0.0
Dim decItemPrice As Decimal = 0.0
Dim decShippingCharge As Decimal = 0.0
Dim decTotalAmount As Decimal = 0.0
'Check For shipping Charge
If intTotalWeightShipped < 10 Then
decShippingCharge = 1.0
ElseIf (intTotalWeightShipped > 10) And (intTotalWeightShipped <= 100) Then
decShippingCharge = 3.0
ElseIf intTotalWeightShipped > 100 Then
decShippingCharge = 5.0
End If
' Calculate Tax
Dim decTax As Decimal = 0.0
If tbStateTextBox.Text = "CA" Then
decTax = decTotalPriceCharged * 0.08
Else
decTax = 0.0
End If
'Calculate Total Order
Dim decTotalAmountWithExpenses As Decimal = 0.0
decTotalAmountWithExpenses = decTotalPriceCharged + decTax + decShippingCharge
'Format Text Boxes
tbDollarAmountTextBox.Text = decTotalPriceCharged.ToString("C")
tbSalesTaxTextBox.Text = decTax.ToString("C")
tbShippingChargeTextBox.Text = decShippingCharge.ToString("C")
tbTotalAmountTextBox.Text = decTotalAmountWithExpenses.ToString("C")
tbNameTextBox.Focus()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Declare Variables
Dim strState As String = "CA"
Dim intItemWeight As Integer = 0
Dim intTotalOrderWeight As Integer = 0
Dim decTotalOrderPrice As Decimal = 0.0
Dim decItemPrice As Decimal = 0.0
Dim decShippingCharge As Decimal = 0.0
Dim decTotalAmount As Decimal = 0.0
'Check For shipping Charge
If intTotalWeightShipped < 10 Then
decShippingCharge = 1.0
ElseIf (intTotalWeightShipped > 10) And (intTotalWeightShipped <= 100) Then
decShippingCharge = 3.0
ElseIf intTotalWeightShipped > 100 Then
decShippingCharge = 5.0
End If
' Calculate Tax
Dim decTax As Decimal = 0.0
If tbStateTextBox.Text = "CA" Then
decTax = decTotalPriceCharged * 0.08
Else
decTax = 0.0
End If
decTax = session("SavedSalesTax")
'Calculate Total Order
Dim decTotalAmountWithExpenses As Decimal = 0.0
decTotalAmountWithExpenses = decTotalPriceCharged + decTax + decShippingCharge
decTotalAmountWithExpenses = session("SavedTotalAmountWithExpenses")
session("SavedTotalPriceCharged ") = decTotalPriceCharged
session("SavedSalesTax") = decTax
session("SavedShippingCharge") = decShippingCharge
session("SavedTotalAmountWithExpenses") = decTotalAmountWithExpenses
End Sub
End Class
|
|
|
|
|
Wow - seems like you have a lot of homework problems...
Why on earth are you saving this stuff in the session ? I would think that one thing you need to check now, is if your session value gets set in several places and is getting stomped. Don't use the session needlessly.
Your first step should be to use the debugger to step through and see if the code is executing as you'd expect. Is tbStateTextBoxes text coming back as CA ? Perhaps you need to use the trim() method to remove a space or two ? A combo box of states would work better than free text, what if someone types 'California', or even 'Cal' or ' CA ' ?
Then, if you can't work it out, post about what you did to try to work it out and post just the relevant code, not so much that we need an hour to work it all out.
I suspect your problem is that you calculate tax first, before the amount you multiply by .08 has a value other than zero. At the core, you need to learn to use the debugger.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|