Click here to Skip to main content
15,889,216 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how to split an excel workbook into two in C# Pin
Richard MacCutchan8-Oct-13 23:24
mveRichard MacCutchan8-Oct-13 23:24 
Questionhey frnds help me out . Pin
Mr.VJ8-Oct-13 21:06
Mr.VJ8-Oct-13 21:06 
AnswerRe: hey frnds help me out . Pin
thatraja8-Oct-13 21:12
professionalthatraja8-Oct-13 21:12 
Questioni have prblrm in ajex auto complite text box need help plz Pin
eng.mohamed ali8-Oct-13 13:33
eng.mohamed ali8-Oct-13 13:33 
QuestionRe: i have prblrm in ajex auto complite text box need help plz Pin
Deflinek10-Oct-13 3:25
Deflinek10-Oct-13 3:25 
QuestionAsp.net Identity MVC5 + Nhibernate Pin
roscez7-Oct-13 6:47
roscez7-Oct-13 6:47 
QuestionProblem reading from sql server view Pin
Member 93288477-Oct-13 6:24
Member 93288477-Oct-13 6:24 
AnswerRe: Problem reading from sql server view Pin
Richard Deeming7-Oct-13 7:22
mveRichard Deeming7-Oct-13 7:22 
Firstly, your post is extremely hard to read, since you haven't formatted your code. Please edit your post and use the code button on the editor toolbar to format your code blocks.

Secondly, you're building a dynamic query, which could leave your code open to SQL Injection[^]. In this case, since you're using hard-coded strings, nothing bad will happen. However, if you forget and later modify the query to include input which is under the user's control, this will become a serious problem. Get into the habit of using parameterized queries even when you're sure that they can't be exploited.

You're executing the query, but you're never actually using the data it returns. You simply call .Read and then close the connection. You need to read the data from the SqlDataReader and do something with it.

You should wrap the SqlConnection, SqlCommand and SqlDataReader variables in a Using block[^], to ensure that they are cleaned up even if the code throws an exception.

Finally, you need to post the details of the exception that's thrown. Saying "the code bombs" isn't enough for anyone to diagnose the problem!

Dim sSql As String = "SELECT [Incident_Number], [COID], [Vendor_Ticket_Number], [Status], [Status_Reason], [Priority], [Owner_Group], [Owner], [Assigned_Group], [Assignee], [Product_Name], [First_Name], [Last_Name] FROM [hca_incident_view] WHERE [Status] = 'In Progress' AND [Company] = 'LifePoint' AND [COID] = @COID"

Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("RemedyConnection").ConnectionString)
    Using sqlCmd As New SqlCommand(sSql, sqlConn)
        
        sqlCmd.Parameters.AddWithValue("@COID", strCOID)
        
        sqlConn.Open()
        Using sqlRead As SqlDataReader = sqlCmd.ExecuteReader()
            While sqlRead.Read()
                ' TODO: Do something with the data here...
            End While
        End Using
    End Using
End Using




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Problem reading from sql server view Pin
Member 93288479-Oct-13 15:39
Member 93288479-Oct-13 15:39 
QuestionEncrypting Parameter value from Right Click Source Code Pin
alok00007-Oct-13 0:13
alok00007-Oct-13 0:13 
QuestionHow to bind multiple rows from data table to single row in Gridview Pin
priyaahh6-Oct-13 23:14
priyaahh6-Oct-13 23:14 
Questionhow to increase performance Pin
antony beula6-Oct-13 21:36
antony beula6-Oct-13 21:36 
AnswerRe: how to increase performance Pin
thatraja6-Oct-13 22:54
professionalthatraja6-Oct-13 22:54 
AnswerRe: how to increase performance Pin
ais076-Oct-13 23:00
ais076-Oct-13 23:00 
SuggestionRe: how to increase performance Pin
Richard Deeming7-Oct-13 1:44
mveRichard Deeming7-Oct-13 1:44 
QuestionHow call secure web service using Jquery Pin
ais076-Oct-13 19:41
ais076-Oct-13 19:41 
QuestionPrincipalContext & UserPrincipal Pin
JD866-Oct-13 19:22
JD866-Oct-13 19:22 
QuestionHey Friends..plz help me out... Pin
Member 103122576-Oct-13 18:57
Member 103122576-Oct-13 18:57 
AnswerRe: Hey Friends..plz help me out... Pin
Member 103122576-Oct-13 18:59
Member 103122576-Oct-13 18:59 
AnswerRe: Hey Friends..plz help me out... Pin
Blikkies6-Oct-13 20:27
professionalBlikkies6-Oct-13 20:27 
AnswerRe: Hey Friends..plz help me out... Pin
ais076-Oct-13 20:39
ais076-Oct-13 20:39 
SuggestionRe: Hey Friends..plz help me out... Pin
Richard Deeming7-Oct-13 1:33
mveRichard Deeming7-Oct-13 1:33 
AnswerRe: Hey Friends..plz help me out... Pin
Richard Deeming7-Oct-13 1:38
mveRichard Deeming7-Oct-13 1:38 
AnswerRe: Hey Friends..plz help me out... Pin
blachsmith7-Oct-13 22:54
blachsmith7-Oct-13 22:54 
AnswerRe: Hey Friends..plz help me out... Pin
CIKolkataDeveloper10-Nov-13 22:40
CIKolkataDeveloper10-Nov-13 22:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.