问题描述
我在Excel中有一个数据源,我有一个格式化的sql sp脚本。
I have a data source in Excel and I have a formatted sql sp script.
我想了解如何通过每列读取excel并格式化SP相应地为每一行编写脚本并使用C#写入文本文件
I want to understand how can I read excel by each column and format SP script accordingly for each row and write to a text file using C#
此外,如果任何列值为零,则应跳过在脚本中添加的行。
Also if any colum value is zero, it should be skipped from getting added in the script.
对于前。我有excel中的数据
For ex. I have data in excel as
Col1 Col2 Col3 Col4 Col5
Col1 Col2 Col3 Col4 Col5
1     0      1      23    1
1 0 1 23 1
1       1      2      231  3
1 1 2 231 3
我的脚本应该准备好了
usp_savemydata @ Col1 = 1,@ Col3 = 1,@ Col4 = 23,@ Col5 = 1
usp_savemydata @Col1=1, @Col3=1, @Col4=23, @Col5 = 1
usp_savemydata @ Col1 = 1,@ Col2 = 1,@ Col3 = 3,@ Col4 = 231,@ Col5 = 3
usp_savemydata @Col1=1, @Col2=1, @Col3=3, @Col4=231, @Col5 = 3
推荐答案
你也可以考虑指出有多少行和列如果列中的所有数据从上到下都是相同的,因为这些数据可以在人们如何回复阅读和检查您的Excel数据时发挥作用。
You might also consider indicating how many rows and columns there are and if all data in columns is the same from top to bottom as these can play a part in how one might reply for reading and inspecting your excel data.
这篇关于从Excel创建SQL存储过程脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!