Build a B1 Form and connect it to your own Database using B1 Studio
The below tutorial shows how to create a B1 user Form and connect it to an SQL Database (Not a normal B1 Company DB ) using C# and B1Studio in VS 2010.
Create SQL Server Database in 3 Steps :
Step 1 – Create a Database
we’ll create a Database using the graphical interface “SQL Server Management Studio”.
From the Windows Start Menu, select “Microsoft SQL Server”, and then “SQL Server Management Studio”. Once the Management Studio starts, right click the Databases folder and select new Database. Enter a name in the “Database name” text box. For this example, well use the name “DemoDB”.
Step 2 – Create a Table
To create a Table, expand the Databases folder, and then expand the newly created “DemoDB” database.
Right click “Tables” and select “New Table”. You will be prompted to fill in “Column Name” and “Data Type”. Fill in “EmpName” with a data type of “varchar(50)”. In the next row, enter a Column Name of age with a data type of “int”.
Save the Table by clicking the Save icon from the top menu bar.
It will prompt for table name, enter “Employees” and click OK.
Step 3 – Enter and View Data
To enter data into the newly created Employees table, expand the Tables folder from the left menu as shown below.
The newly created Employees table will be listed. Right click it and select “Open Table”. A small grid will open. Enter a few data lines as shown below. Moving to a new line after entering data automatically saves.
Create a B1 Add-on Project
Select File->New Project within the SAP Business One studio for Visual Studio 2010 IDE. This will bring up the New Project dialog. Click on the “Visual C#” node in the tree-view on the left hand side of the dialog box and choose the “SAP Business One” icon:
Visual Studio will then create and open a new web project within the solution explorer. By default it will have a single form (Form1.b1f).
Open and Edit the form
Double click on the Form1.b1f page in the solution explorer to open and edit the form. Add a button, a grid and DataTable DataSource to the form from the ToollBox in the left side.
In the properties of the grid, Link it to the DataTable DT_0
In the properties of the button, Attach a Pressed_After Event to it, in order to Bind the Grid to the Employees table from the DemoDB Database
Double click on the PressedAfter tab and write the code below :
Finally, Run your program by clicking Debug > Start Debugging (or Start Without Debugging). Or just press the F5 key on your keyboard . Your program will look like this:
Let me know your feedBack 🙂