3
Answers

Stored Proc Return Value

Administrator

Administrator

21y
2.4k
1
I am using a stored procedure to insert a record in SQL Server. The primary key is created at the time of the insert. Can I return the key if the insert succeeds? The initial insert creates a record in an author table. Once that is done I want to redirect the user to a page where they can start inserting rows for the books by that author. I need the primary key for the new author row to create the publications row. I am using C#. Code for the insert: SqlConnection objConn = null; SqlCommand objCmd = null; strDBConn = ConfigurationSettings.AppSettings["ConnectionString"]; objConn = new SqlConnection( strDBConn ); objCmd = new SqlCommand( ); objCmd.Connection = objConn; DataSet objDataSet = new DataSet( ); SqlDataAdapter objAdptr = new SqlDataAdapter( ); objCmd.CommandText = "p_insertAuthor"; objCmd.CommandType = CommandType.StoredProcedure; SqlParameter objParam; objParam = objCmd.Parameters.Add("@name",sAuthor ); objParam = objCmd.Parameters.Add("@desc", sDesc); objParam = objCmd.Parameters.Add("@country", sCountry); if( objConn.State != ConnectionState.Open){ objConn.Open( ); } objAdptr.SelectCommand = objCmd; SqlDataReader objReader; try{ objReader = objCmd.ExecuteReader(); objReader.Close( ); objConn.Close( ); } catch (SqlException objError) { objConn.Close( ); Response.Write(objError.Message); }
Answers (3)
0
huddo23

huddo23

NA 3 0 19y
Thanks alot for that your reply made more sense than most books ive read...lol Thanks Huddo
0
spgilmore

spgilmore

NA 591 0 19y
This is very simple. Just draw a line in the new color between the same two points and it will be overdrawn. GDI+ is not a collection of primitives objects. It is a Graphics object (like a canvas) which has pixels of various colors. Nothing more. If you want to change those colors, you use the various GDI+ methods to draw primitives and images in various ways. Once that operation is finished, the line, the blit, the circle etc. is not really there anymore, only the changed pixels on the Graphics canvas remain. So when you draw a line on the canvas in red, there is no line whose color can be changed. There is only a canvas whose pixels can be overdrawn. Note that this does not preclude your ability to devise a system that works that way. You can define objects that represent these primitives and keep references to them, then render them on the Graphics object on demand. You could then modify the color property or the dimensions of these primitives at any time and re-render them to display the result. This is how many programs work, but you have to implement all that yourself.
Next Recommended Forum