|
you have good examples on this in 4guysfromrolla!!!
Gautham
|
|
|
|
|
Hello & smiles,
Can someone kindly guide as to what is going wrong in my Sub below? I am getting the error as :
System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_ProfitLossData_CBValues". The conflict occurred in database "ProfitLossRegister", table "dbo.CBValues", column 'cbno'. The statement has been terminated.
------------------------------------------------------------------------------------------
Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim connectionsave = New SqlConnection(ConnectionString)
Dim Commandsave As SqlCommand
Dim forecastbox As String
Dim commentbox As String
Dim catvalue As String
Dim CBVal As String
Dim PLGridRow As GridViewRow
Commandsave = New SqlCommand
Commandsave.Connection = connectionsave
Try
connectionsave.open()
'iterate through all the gridrows
For Each PLGridRow In PLForecastGrid.Rows
forecastbox = CType(PLGridRow.FindControl("txtforecastbdgt"), TextBox).Text
commentbox = CType(PLGridRow.FindControl("txtcomments"), TextBox).Text
catvalue = PLGridRow.Cells(0).Text
lbltest1.Text = catvalue
CBVal = PLGridRow.Cells(1).Text
lbltest2.Text = CBVal
Commandsave.CommandText = " Insert into profitlossdata"
Commandsave.CommandText += " (forecastbdgt,comments,branchno,yearno,"
Commandsave.CommandText += " bpno,catno,cbno)"
Commandsave.CommandText += " Values ('" & forecastbox & "', "
Commandsave.CommandText += "'" & commentbox & "', "
Commandsave.CommandText += "'" & lblbrvalue.Text & "', "
Commandsave.CommandText += "'" & lblyrvalue.Text & "', "
Commandsave.CommandText += "'" & lblbpvalue.Text & "', "
Commandsave.CommandText += "'" & lbltest1.Text & "', "
Commandsave.CommandText += "'" & lbltest2.Text & "')"
Commandsave.ExecuteNonQuery()
Next
lblmessage.Text = " Records Created!"
Catch ex As Exception
lblmessage.Text = ex.ToString
Finally
connectionsave.close()
End Try
End Sub
------------------------------------------------------------------------------------------------
'cbno' is a foreign key on my table. The values of cbno are displayed on the gridview with a Join when the grid loads. I have to save these values in my master table so I am reading the the value of cbno for each row in a label(with findcontrol) and then inserting this label value into the mastertable but in the cbno column which is a foreign key.
I hope I haven't confused you all. Please help!
Thank you.
Aartee.
...HE is watching Us All!
|
|
|
|
|
Probably the problem has nothing to do with the gridview. Just check the values you are inserting as foreign key in the table, whether it exests in the master table or not.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi Apurva,
Thankyou for your prompt reply.
In my gridview the values are coming from CBValues table & CbNo is ID of that table and foreign key of my master (profitlossdata) table. I am populating my gridview with CBNo and some other template columns. Then I am trying to insert these values into my master table on a button click event as in the sub in my previous post, so these values will exist in master table only if the Insert statement works, and that is my problem, the insert stt is failing... or am I confused?...well it's 3:30pm in Adelaide I guess my brain is off for a nap.
Can you kindly explain it a bit more in detail?
Thanks a million.
Aartee.
...HE is watching Us All!
|
|
|
|
|
The only problem what I can guess is some ID(which you are inserting in the second table as a foreign key) does not belong to the first table(i.e. ID not there in the first table). Can you check them again?
Best Regards,
Apurva Kaushal
|
|
|
|
|
The DRP System use asp.net tech and Sql server 2000
3 level tech architcture.
www.drpsky.com
Good friend
|
|
|
|
|
congratulations...
Best Regards,
Apurva Kaushal
|
|
|
|
|
Hi all,
I want to display employee photo whenever he logs in. I am not storing the url of photo in database instead i have created a folder in which the photo is saved with empid name.I want that if the photo doesn`t exist a default pic to be shown.If the photo exists in the folder,the pic be shown. how do i achieve this.
Thankx in advance.
|
|
|
|
|
So what exactly is the problem you are having? What you need to do is to find the reuired image in the folder and if not found display the default image.
Best Regards,
Apurva Kaushal
|
|
|
|
|
hi
let us say u have an image object. it has a property imageurl which u can set at runtime. since u r knowing the empid of the user logging in its easy for u to trace the imagename from the source directory. the only thing u have to check whether the image exists r not. try this and see. if it has any prob let me know for further asst.
|
|
|
|
|
Where`s the code???
I just want to check whether the photo exists or not.What happens is i set the URL as IMG1.Src="c:\\"+empid+".jpg" .But if the photo is not present it displays nothing(it`s obvious).What to do???
|
|
|
|
|
Prior to set the src to the image you need to search for the image. This you can do with simple file handling objects.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Sorry,but i have no knowledge of handling files. Can u give me the code ..
Please..
|
|
|
|
|
You can use System.IO.File.Exists("path") to check whether file exists or not.
Best Regards,
Apurva Kaushal
|
|
|
|
|
|
Always welcome..
Best Regards,
Apurva Kaushal
|
|
|
|
|
hi
iam sorry. i didnot know that u wanted the code.anyways did u get it r not.
|
|
|
|
|
i have pasted a sample code.
here label1.text stands for ur empid
iam using a image server control
i created a folder in the app path named photo where i stored my sample pics
this is how i accessed and set the object. i hope u can modify further acc to ur reqts.
Dim s As String = CurDir()
Dim s1 As String = s & "\Photo"
Dim s2() As String
Dim s3 As String
Dim i As Integer
Dim j As Integer
Label1.Text = "yasoda2"
If Directory.Exists(s1) Then
s2 = Directory.GetFiles(s1)
For i = 0 To s2.Length() - 1
j = s2(i).IndexOf(".")
s3 = Left(s2(i), j)
If (s3 = s1 & "\" & Label1.Text) Then
Image1.ImageUrl = s2(i).Replace(s, "~")
End If
Next
Else
Console.Write("Directory dose not exist")
End If
|
|
|
|
|
hi all,
i have 2simple doubts
1.first one is about Directories in ASP.NET. what are Directories available with ASP.NET??
if i am not wrong are they virtual directories and active directories?? some one asked me today, i am not sure about the answer. i tried to google but not found helpfull info.
2.please can anyone tell me what is (VS.71) here in the Url?? i mean is it a quesry string which is passing to server?? recently i took one assessment test, in that i got similar type of question. they gave me 4 choices but unfortunately i didn't remember them. now when i googling something about directories then i saw the url in the address bar, so want to clarify my doubt.
http://msdn2.microsoft.com/en-us/library/aa719551(VS.71).aspx
thanks,
Rahi
-- modified at 18:35 Wednesday 7th February, 2007
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
You have doubts or questions?
1) active directory has nothing to do with ASP.NET. If you searched google for the term you would have found that information.
2) It is probably a url that is generated dynamically from a virtual path or url rewrite mechanism.
only two letters away from being an asset
|
|
|
|
|
hi Mark,
u r correct. these are not doubts. these are questions. i tried goolge using "ASP.NET directories" but unable to found the exact info. i found how to ceate a directory, ... but not exact info what i am looking for. if some one asks us about ASP.Net Directories...what we should answer?? i mean why we use and how we use that's it?? but they were asking me types of directories....
thanks for the Response,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
Rahithi wrote: what we should answer??
Ask them to clarify the question.
Sounds like an interview question that you failed.
only two letters away from being an asset
|
|
|
|
|
nope! it's not an interview question. u guessed wrong!
Thanks,
Rahi
If you look at what you do not have in life, you don't have anything,
If you look at what you have in life, you have everything... "
|
|
|
|
|
hi friends
how to send the sms through wepapplication in asp.net
regards
saravanan
|
|
|
|
|
this[^] will help you.
Best Regards,
Apurva Kaushal
|
|
|
|