The SQL Server Express Edition

Joined
Feb 21, 2018
Messages
216
Reaction score
86
I am trying to load customer names into combobox2 from a stored-procedure....instead of the eight customers names its my code is showing FormUI.Cust. I placed a breakpoint on the statement which clearly shows there are eight customer names .... buts I don't know why... instead of customer names it's loading eight times {FormUI.Cust}...
Can you please help?


upload_2018-4-28_10-30-28.jpeg
 

Abraham Andres Luna

Child of God
Joined
Mar 14, 2018
Messages
699
Reaction score
227
After you set the DataSource of the comboBox2, then you have to set which column of the DataSource is the Text, and which column is the Value.
 
Joined
Feb 21, 2018
Messages
216
Reaction score
86
Thanks to all of you, I am now able to write c sharp applications, stored procedures in SQL Server etc etc...
One thing I failed to search in web is that I want to generate blank records ( a record for each cheque in my cheque book) that would require a for next look in a stored procedure, I will give starting cheque number and the quantity of checks in the check book....the stored procedure should generate blank record for each cheque...

Can you please help in rectifying my stored procedure code (given below):

USE [CHQ]
GO
/****** Object: StoredProcedure [dbo].[CHQ_Insert_Genrate_New_ChqBook] Script Date: 5/14/2018 11:44:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CHQ_Insert_Genrate_New_ChqBook]
@MyCounter int,
@BankCode nvarchar(100),
@ChequeNo float,
@QtyOfChq int


AS
BEGIN


SET @MyCounter = 1 -- to use this multiple times you can just

-- change the starting number and run again
-- if you do not want duplicate numbers

WHILE @MyCounter < @QtyOfChq -- any value you want
set @ChequeNo = @ChequeNo + @MyCounter - 1
BEGIN

INSERT INTO dbo.CHQPayments([Cheque No],BankCode)
VALUES

(@ChequeNo,@BankCode) -- insert counter value into table

set @MyCounter = @MyCounter + 1
END
End

Its not returning any error message...but it keeps on running without any result...
The values as displayed in sql text are:

USE [CHQ]
GO

DECLARE @return_value int

EXEC @return_value = [dbo].[CHQ_Insert_Genrate_New_ChqBook]
@MyCounter = 1,
@BankCode = N'BBB-FR-347123456789',
@ChequeNo = 1000001,
@QtyOfChq = 10

SELECT 'Return Value' = @return_value

GO
 
Last edited:
Joined
Feb 21, 2018
Messages
216
Reaction score
86
Thanks to Tim Corey for responding to my query. He said:
There are a few things going on here. First, you are approaching a stored procedure like it is code. That isn't what you want to do in most cases. Doing so limits the power of SQL. Instead, you need to treat it like it is just a database. That means that a stored procedure has one job and that is to process one record. Doing while loops in a stored procedure (or any SQL code) is inefficient. Try to avoid conditional logic, looping logic, or any other complexities if possible. Second, why would you insert multiple records based off of one piece of data? If that is really what you want to do, do this work in C# and make a stored procedure call for reach record (put the while loop in C#). Finally, you are mixing types here (int and float), which can cause conversion issues. Try to keep them the same type if possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top